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

Recommended Answers

What is ur problem? or where is the probelm?

Jump to Post

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?

Jump to Post

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.

Jump to Post

All 9 Replies

What is ur problem? or where is the probelm?

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

the condition i have set doesn't work.. thanks

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.

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.

thanks for the suggestion.. got an idea. :) and it works :)

What is ur sollution ? And if it solved then plz mark the thread as solved..

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.