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
 General SQL Server Forums
 New to SQL Server Programming
 Connection string error VS2010
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

12 Posts

Posted - 11/09/2012 :  11:44:15  Show Profile  Reply with Quote
Using the data source wizard to create a data connection to a SQL database in VS2010. The following code was created:


I assume ( probably wrongly) that since the text boxes and combobox that are bound to this database contain the correct data that a connection has been established and the dataset filled. So I want to query this data with a selected change event. I declare global variables

Dim strprocess As String
Dim strpart As String = Nothing

Then under the selected change event I use:

 strprocess = cboprocess.SelectedValue

             strpart = "SELECT PartNumber FROM tblParts WHERE Process = @Process"
        Dim cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand(strpart)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@Process", strprocess)

        Dim someDatatable As New DataTable
        Dim myReader As SqlClient.SqlDataReader = cmd.ExecuteReader
        If myReader.HasRows Then
        End If

The above code should take the selectedvalue of cboprocess put in the query and return a value to strpart. Then I will bind the results to cbopartnmber. When running the code I receive this error:

ExecuteReader: Connection property has not been initialized.

I think generally this means the connection is not open but itf its not open how is there data in the dataset. Is the datasource wizard a big POS?

Flowing Fount of Yak Knowledge

5155 Posts

Posted - 11/09/2012 :  11:56:15  Show Profile  Reply with Quote
You need a connection object attached to the command object. See example on this page:
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