Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 ExecuteReader: Connection property has not been in

Author  Topic 

dam123
Starting Member

1 Post

Posted - 2013-02-13 : 11:05:16
These are my code below. i tried it on click event it keep returning this error ExecuteReader: Connection property has not been initialized

Protected Sub Btinfor_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btinfor.Click
Dim cmddata As New SqlCommand("SELECT Age FROM data Where Origin =" & DDOrigin.SelectedItem.Text)

Dim sqlDR As SqlDataReader

sqlDR = cmddata.ExecuteReader()

GDinfor.DataSource = sqlDR
GDinfor.DataBind()

sqlDR.Close()


End Sub

Source Error:


Line 32: Dim sqlDR As SqlDataReader
Line 33:
Line 34: sqlDR = cmddata.ExecuteReader()
Line 35:
Line 36: GDinfor.DataSource = sqlDR


Source File: C:\Users\peter\Desktop\WebSite1\UsingDataReaders.aspx.vb Line: 34


please i need ur help to resolve this problem. thanks

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-02-13 : 11:26:17
You need to set the connection property of the command object to an instance of the SqlConnection object. Alternatively, you can use a different constructor of the SqlCommand object that takes a connection string property (which will then construct the connection object for you). That connection object describes how to connect to your server. Take a look here for an example - what you want is the SqlClient example: http://msdn.microsoft.com/en-us/library/dw70f090.aspx
Go to Top of Page
   

- Advertisement -