Retrieving data using a datareader and stored procedure
Posted on 2009-04-01
I'm using VS 2008 and SQL server (sqldatasource1) on Win XP Professional coding in VB.net.
I want to create a datareader that uses a stored procedure as the datasource. This datareader will contain the data from the stored procedure which I will use to display the data from the fieldnames in labels. Could someone show me how to code this?
The stored proc is called SearchOrg
My labels are OrgName, OrgLocation, OrgManager
Someone helped me with this, but didn't give more detail due to time constraints....
Dim dr as New Datareader
Dim cmd as New SqlCommand
(I dont know if I should use SqlCommand or SqlDatasource, please advise)
For the labels
lblOrgName.Text = dr("fieldname").ToString
I saw the following code in vs2008 dynamic help, but I really dont' understand it, where to put it or how to bind the reader to my labels.
Private Sub HasRows(ByVal connection As SqlConnection)
Dim command As SqlCommand = New SqlCommand( _
"SELECT CategoryID, CategoryName FROM Categories;", _
Dim reader As SqlDataReader = command.ExecuteReader()
If reader.HasRows Then
Do While reader.Read()
& vbTab & reader.GetString(1))
Console.WriteLine("No rows found.")
I'd really appreciate your help!