question

shronfernando avatar image
shronfernando asked

Pass DB Value to a vb.net variable

Below code gives me an error : "No value given for one or more required parameters" Help please!!!

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click                    
                    
Dim Var1 As String = MaskedTextBox4.Text                    
                    
QueryString = "SELECT Table_ID FROM ULD_Data_Master WHERE ULD_Serial_Nbr = " & Var1 & ""                    
                    
If Connection.State = ConnectionState.Closed Then                    
    Connection.Open()                    
End If                    
                    
Dim Command As New OleDb.OleDbCommand(QueryString, Connection) 'OleDb command to choose the fields                    
                    
Dim PassID As Integer = Command.ExecuteNonQuery                    
                    
'Assign_Add_Data(PassID)                    
                    
End Sub                    
sql-server-2005
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
AjarnMark avatar image
AjarnMark answered

The return value for ExecuteNonQuery on a SELECT statement is -1. Try using Command.ExecuteScalar in order to return the first column of the first row in the result set, which would be your Table_ID value.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.