SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 Other Forums
 MS Access
 ExecuteReader: Connection property has not been in
 New Topic  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

3849 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: http://msdn.microsoft.com/en-us/library/dw70f090.aspx
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.03 seconds. Powered By: Snitz Forums 2000