Dim addSupplier As String
addSupplier = "insert into Suppliers (CompanyName, ContactPerson, Street, City, State, ContactNumber) values (" & _
WrapQuote(tbCompanyName.Text) & COMMA & _
WrapQuote(tbContactPerson.Text) & COMMA & _
WrapQuote(tbStreet.Text) & COMMA & _
WrapQuote(tbCity.Text) & COMMA & _
WrapQuote(tbState.Text) & COMMA & _
WrapQuote(tbContactNumber.Text) & ")"
cmdUser = New SqlCommand(addSupplier, conn)
Dim ID As Integer
conn.Open()
cmdUser.ExecuteNonQuery()
cmdUser.CommandText = "Select Scope_Identity() Statement"
ID = cmdUser.ExecuteScalar
Dim addLab As String
addLab = "insert into Laboratory (LaboratoryID,LaboratoryName,Location) values (" & _
WrapQuote(ID) & COMMA & _
WrapQuote(cmbLab.SelectedItem) & COMMA & _
WrapQuote(tbLocation.Text) & ")"
cmdUser = New SqlCommand(addLab, conn)
cmdUser.ExecuteNonQuery()
cmdUser.CommandText = "Select Scope_Identity() Statement"
ID = cmdUser.ExecuteScalar
Label1.Text = ID
MsgBox("saved")
conn.close()
this code is located on my save button. i get this "Conversion from type 'DBNull' to type 'Integer' is not valid" error on "ID = cmdUser.ExecuteScalar at the 2nd block of codes('addlab') it has a value of 1 which is correct as i wanted to get the ID from supplier and then pass it to the laboratory. what may be the cause of the error? help

New Topic/Question
Reply



MultiQuote





|