Getting data from MySql database in to TextBoxes using multiple WHERE

nigelsvision nigelsvision 96 Reputation points
2021-05-17T17:37:20.227+00:00

Hi, I am using VB.NET win forms. I have multiple TextBoxes on my form and I am fetching data from a MySQL database like so. It does work I just want to add an extra clause to check.

Try
            mySQLcon = New MySqlConnection("Data Source=My IP; userid=My Username; password=My Password; database=Database name")
            cmd.Connection = mySQLcon
            cmd.CommandText = ("select TrailerMOTDate,TrailerServiceDate,TrailerLocationMOT,TrailerLocationService FROM TrailerNumbersTbl WHERE TrailerNumber='" + TrailerTxtBox.Text + "'")
            mySQLcon.Open()
            Dim lrd As MySqlDataReader = cmd.ExecuteReader()
            If lrd.HasRows Then
                lrd.Read()
                MotDateTxtBox.Text = lrd.GetValue(0).ToString()
                ServiceDate.Text = lrd.GetValue(1).ToString()
                MOTLocation.Text = lrd.GetValue(2).ToString()
                ServiceLocation.Text = lrd.GetValue(3).ToString()
                mySQLcon.Close()
            Else
                MsgBox("Select a trailer first")
            End If
        Catch ex As Exception
            MessageBox.Show("Hmm you have come across an error ")
        Finally
        End Try

I want to add an additional check i.e. I have the company name in a label on my form the company label is called CompanyName.Text

Where I have got this

WHERE TrailerNumber='" + TrailerTxtBox.Text + "'")

I want add an AND CompanyName.Text which would help make it more secure

Can someone help me with this?

Thanks

Developer technologies VB
0 comments No comments
{count} votes

Accepted answer
  1. nigelsvision nigelsvision 96 Reputation points
    2021-05-17T18:35:53.853+00:00

    So the answer was easier than I thought

    WHERE Company= '" + CompanyHeader.Text + "' AND TrailerNumber='" + TrailerTxtBox.Text + "'")

    Thanks anyway

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.