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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 Other Forums
 MS Access
 ExecuteReader: Connection property has not been in
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

1 Posts

Posted - 02/13/2013 :  11:05:16  Show Profile  Reply with Quote
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


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
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 02/13/2013 :  11:26:17  Show Profile  Reply with Quote
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:
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000