0

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

4
Contributors
9
Replies
13
Views
5 Years
Discussion Span
Last Post by Begginnerdev
0

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

0

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?

0

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 by Begginnerdev: n/a

0

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.

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.