i am new to VB.net. just want to check an id number in my textbox if its aldready existed in my database. this is my condition:

if textbox1.text = ds.tables("employees").row(0).item("id") then

msgbox("ID already exist")

end if

this is the error i have encounter...object reference not set to an instance of an object

ds.tables("employees").row(0).item("id") only one row ur checking? Cant u validate at the back end? by just sending ur employee id as parameter?

If you are wanting ID's to be unique, you might want to think about making it a primary key. Thus making it not possible to have multiples. Then you can wrap your insert in a try catch, the client will handle the "No duplicate keys" message.

Edited 4 Years Ago by Begginnerdev: n/a

Make it the Primary Key then set it to autoincrement and the database will assign an id for you, no need to worry about it in the code.

You can try:

'sqls is a string
'cmd is a command builder

sqls = "SELECT * FROM employees WHERE id = '" & textbox1.text & "'"

cmd = New CommandBuilder(sqls,connection)
If cmd.ExecuteNonQuery = False Then
     MsgBox("ID not found")
End If
This question has already been answered. Start a new discussion instead.