Hello Group,

I'm beginning to understand the connections required to return information from your database. I'm now trying to return multiple lines from the database that have the same "prefix" within the part number. As my example, I have two records within my database that both start with "AO0025". I need to return both examples to two combo boxes. Here is what my code looks like now:

        Dim connstr = "Data Source=.;AttachDbFilename=C:\Users\Don\Documents\DataDesignSolutions.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
        Dim search1 As String = "'%" & txbxCustomerName.Text & "%'"
        Dim connection As SqlConnection = New SqlConnection(connstr)

        Dim command As SqlCommand = connection.CreateCommand()
        command.CommandText = sqlquery
        Dim reader As SqlDataReader = command.ExecuteReader()
        cbxPartNumber.Visible = True
        txbPartDesc.Visible = True
        cbxPartNumber.Text = reader.GetString(0)
        txbPartDesc.Text = reader.GetString(1)

Currently I've made provisions for 1 combobox and 1 textbox to list the partnumber and the part description. I know I'll need to add another combobox and textbox to show the second record. But how do I return both records?

In advance, thanks for your help!


Look at the example here which also shows you how you should be forming your queries using parameters rather than concatenation.

By the way, if you are using SQL Server you should not be specifying the name and location of the database file. You should let the database server handle that and just refer to the database name. You'll see how that is done in the example as well.

Rev Jim, I've fixed the issue regarding the name and location of the database. Unfortunately I'm having trouble establishing a sql database password in the user 'sa'. I've sent a new question out regarding it. If you can help, please do.


This question has already been answered. Start a new discussion instead.