Last post Jan 31, 2013 07:45 AM by ahmedsaid50
Jan 30, 2013 03:30 AM|ahmedsaid50|LINK
I am creating a website using VB.net ASP.net and I want to check if the ID of the client is exsit or not. If it exsits a message appears in a label on the website and say "ID exsit" otherwise it adds the information to the users table.
I can add the new data to the database but i need to check whether the ID exsits or not before excuting the insert code.
Jan 30, 2013 04:36 AM|ashkc|LINK
in the insert stored procedure just check for ID it is exist or not in the tables..
if not exists then insert other wise display message like ID existed
Jan 30, 2013 05:58 AM|ahmedsaid50|LINK
Thank you for your reply; but i need to do this using the vb.net in the webform not on the database.
Jan 30, 2013 03:24 PM|Andrew Morton|LINK
You just need to query the database, perhaps like this:
Friend Function IdExists(id As String) As Boolean
Dim exists As Boolean = False
Dim conn As New SqlConnection("yourConnectionString")
Dim sql = "SELECT COUNT(*) FROM [yourTableName] WHERE [Id]=@Id;"
Dim sqlCmd As New SqlCommand(sql, conn)
exists = (CInt(sqlCmd.ExecuteScalar()) <> 0)
Catch ex As Exception
' something went wrong '
Jan 31, 2013 06:09 AM|NiravVyas|LINK
I think you are trying to say that you dont want to make trip to database to check if ID exists or not, and decide from code itself. Unfortunately you cant do that. One way is as suggested by
Andrew Morton in above post, other way is to populate all the IDs in some list at page load (it will be good only if you are calling database at pageload for some purpose) and check id entered in textbox using code itself.
Jan 31, 2013 07:45 AM|ahmedsaid50|LINK
Thank you everyone who replied to my post.
Thank you Andrew for your help.
I tried your code and made some changes to go with my code and it worked.