If SQL query returns no values, msgbox?

Wabster

Member
Joined
Oct 1, 2009
Messages
7
Programming Experience
Beginner
Hi,

Have a small app I am working on and it works fine, until it cannot find the item queried - Where it throws an error.

Any ideas?

VB.NET:
'Check if item code is blank or not
        If TextBox1.Text = "" Then
            MsgBox("Please enter an item code", MsgBoxStyle.Critical, "Error!")
        Else
            'Create a Command object.
            myCmd = myConn.CreateCommand
            myCmd.CommandText = "SELECT BLAH, BLAHBLAH FROM BLAH
WHERE BLAHBLAH=('" & TextBox1.Text & "');"

            'Open the connection.
            myConn.Open()
            myReader = myCmd.ExecuteReader()
            'Concatenate the query result into a string.
            myReader.Read()
            results = myReader.GetValue(0)
            results1 = myReader.GetValue(1)
I want it to show a msgbox if query returns nothing, instead of trying to myReader.Read() which throws an error.

I know its going to be if/elseif - But what am I "If x = y" ing ??
 

Latest posts

Back
Top