Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB SQL SQL-Server
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"
 
        Try
            conn.Open()
            
        Catch ex As SqlException
            MessageBox.Show(ex.Message)
Posted 19-Mar-13 9:10am
Comments
Sergey Alexandrovich Kryukov at 19-Mar-13 14:16pm
   
What prevents you from reading DataReader documentation?
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
 
You can Try below code, where i fill the gridview by using DataAdapter.
 
1. define connection string in web.config file.
<connectionstrings>
<add name="ConnectionStringName" connectionstring="Data Source=abc;Initial Catalog=xyz;User ID=mno;Password=pqr" />
</connectionstrings>
 
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)
        GridView1.DataBind()
    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()
        da.Fill(dt)
        Return dt
    End Function
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 400
1 Jochen Arndt 200
2 Richard MacCutchan 135
3 DamithSL 95
4 Maciej Los 95
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,032
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,220


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 21 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100