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 sqlquery = "SELECT [ARC-CUSTOMER-NAME], [ARC-CUSTOMER-NUMBER] FROM [AR_CUSTOMERS] where [ARC-CUSTOMER-NAME] like " & search1
        Dim connection As SqlConnection = New SqlConnection(connstr)
        connection.Open()

        Dim command As SqlCommand = connection.CreateCommand()
        command.CommandText = sqlquery
        Dim reader As SqlDataReader = command.ExecuteReader()
        reader.Read()
        frmPopup.Show()
        frmPopup.Controls.Add(cbxPartNumber)
        frmPopup.Controls.Add(txbPartDesc)
        cbxPartNumber.Visible = True
        txbPartDesc.Visible = True
        cbxPartNumber.Text = reader.GetString(0)
        txbPartDesc.Text = reader.GetString(1)
        connection.Close()

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!

Don

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.

Don

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.