Hello,
I'm trying to query a sql table to see if a value already exists.
I can get that to return the field correctly. But, if the row doesn't exists, it errors out. Is there any way to check for that null rows? Also, is this a good way to be checking for values? Thanks.
I'm trying to query a sql table to see if a value already exists.
Code:
strMAC = "11:22:33:44:55:66"
Call MsgBox(QueryDB("SELECT * FROM main WHERE MAC = '" & strMAC & "'", conn))
Function QueryDB(ByVal sql As String, ByVal conn As SqlConnection)
QueryDB = 0
Dim cmd As SqlCommand = Nothing
Dim dr As SqlDataReader = Nothing
cmd = New SqlCommand(sql, conn)
dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
dr.Read() ' Read one row from the table
QueryDB = dr(0)
End Function
Comment