paulthepaddy
Well-known member
hey guys, i understand what is happening here im, just not sure of how to work around it.
If i pass a Reg that does exist in the Database then everything works fine, BUT when i pass a Reg that ISN'T in the DB it is giving a null reference error. which i understand the select Statement should only return a row so if it returns nothing then the scalar is nothing, does anyone of a fix or a better way to get the job done.
Thanks
VB.NET:
Public Function CarExists(reg As String) As Boolean
Using constring As New OleDb.OleDbConnection(My.Settings.DBConnectionString)
Dim DA As New OleDb.OleDbDataAdapter
DA.SelectCommand = New OleDb.OleDbCommand("SELECT Reg FROM Cars WHERE Reg = @Reg", constring)
DA.SelectCommand.Parameters.AddWithValue("@Reg", reg)
constring.Open()
Return If(DA.SelectCommand.ExecuteScalar.ToString = reg, True, False)
constring.Close()
End Using
End Function
If i pass a Reg that does exist in the Database then everything works fine, BUT when i pass a Reg that ISN'T in the DB it is giving a null reference error. which i understand the select Statement should only return a row so if it returns nothing then the scalar is nothing, does anyone of a fix or a better way to get the job done.
Thanks