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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Connection string error VS2010
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mulefeathers
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:

Me.TblPartsTableAdapter.Fill(Me.KanbanDataSet.tblParts)

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
            someDatatable.Load(myReader)
        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?

sunitabeck
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:
http://msdn.microsoft.com/en-us/library/dw70f090.aspx?cs-save-lang=1&cs-lang=vb#_SqlClient
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.06 seconds. Powered By: Snitz Forums 2000