Group,

I'm stuggling to get values from an sql database table into several textboxes. I'm not getting an error, but I'm also not getting anything to show up in these textboxes. Can you offer some thoughts as to what I need to do to fix this?

Private Sub btnUpdateOrder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdateOrder.Click

        Dim con As New SqlConnection
        Dim cmd As New SqlCommand
        Dim string1 As String = txbPartNo.Text.Trim
        Dim search1 As String = "'" & string1 & "'"

        Try
            con.ConnectionString = ("Data Source=DON-PC;Initial Catalog=DataDesignSolutions;Integrated Security = True;User ID=DON-PC;Password=be67011;")
            cmd.Connection = con
            cmd.CommandText = "SELECT [INV-DESCRIPTION], [INV-UNIT-MEASURE], [INV-SELL-PRICE-1] FROM INVENTORY WHERE [INV-PART-NUMBER] LIKE " & search1
            con.Open()
            Dim rdr As SqlDataReader = cmd.ExecuteReader
            While rdr.Read()
                txbDesc.Text = Convert.ToString(rdr("[INV-DESCRIPTION]"))
                txbUM.Text = Convert.ToString(rdr("[INV-UNIT-MEASURE]"))
                txbPrice.Text = Convert.ToString(rdr("INV-SELL-PRICE-1"))
                rdr.Close()
            End While
        Catch ex As Exception
            MessageBox.Show("Error while retrieving records on table..." & ex.Message, "Load Records")
        Finally
            con.Close()
        End Try

    End Sub

Thanks for your assistance,

Don

Recommended Answers

All 5 Replies

Hi,

Change this line:

Dim search1 As String = "'%" & string1 & "%'"

Keep a BreakPoint on this line... "cmd.CommandText"
and check the SQL Query...

Regards
Veena

Hi
i need great help for vb 2008 . i wanna make srs manager software on vb. and the first i need to show database in list box.can any one suggest me code.

@akeera - Please start a new thread and show us you have made some effort by providing some code.

@Don - I'll say it one more time. If you specify integrated security then you don't need a userid and password. You are authenticated by your windows logon.

I hate to admit this, but the problem I've had all along with with the part number within the database. It seems when I pushed the part number up, it went up with a bunch of spaces at the end. I did make a change to the code on two ends and got it to run perfectly. At the bottom end, I changed the code there to read:

Dim rdr As SqlDataReader = cmd.ExecuteReader
        Do While rdr.Read()
            txbDesc.Text = rdr(1)
            txbUM.Text = rdr(2)
            txbPrice.Text = rdr(3)
        Loop

When running it step by step, I decided to see if some of the problem may have been with the part number itself. So I tried this at the top:

Dim search1 As String = "'" & string1 & "%" & "'"

Putting that wildcard at the end made all the difference. It runs like a champ.

Rev. Jim, I'm no longer testing this in Windows Authentication mode. I have gone in and established a password for 'sa'. I'm now running this in SQL Server Authentication mode.

Thanks again for everyone's help.

Don

I have gone in and established a password for 'sa'.

Then you shouldn't be using trusted connection and you should definitely not be using the sa account for app work. You should create another sql account for that.

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.