Click here to Skip to main content
15,942,710 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi how can i use the SqlDataReader to read all the columns within the table seraching by id here is part of my code

selectCommand.CommandText = "SELECT * FROM tblEjemplo WHERE COOP_ID = @COOP_ID"


    Catch ex As SqlException
Sergey Alexandrovich Kryukov 19-Mar-13 14:16pm    
What prevents you from reading DataReader documentation?


You can Try below code, where i fill the gridview by using DataAdapter.

1. define connection string in web.config file.
<add name="ConnectionStringName" connectionstring="Data Source=abc;Initial Catalog=xyz;User ID=mno;Password=pqr" />

2. Import some namespace.
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration

3. Now call function BindGridView(COOP_ID) to fill GridView by using DataAdapter, where i am passing COOP_ID = 1 you can pass as per your need.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        GridView1.DataSource = BindGridView(1)
    End Sub

    Private Function BindGridView(ByVal COOP_ID As Integer) As DataTable
        Dim connstr = ConfigurationManager.ConnectionStrings("ConnectionStringName").ConnectionString
        Dim con As SqlConnection = New SqlConnection(connstr)
        Dim da As SqlDataAdapter = New SqlDataAdapter("SELECT * FROM tblEjemplo WHERE COOP_ID = " + COOP_ID + "", con)
        Dim dt As New DataTable()
        Return dt
    End Function
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900