I am a beginner coder, i am building a project using C# Asp.Net in which i am registering users with a user id, now my question is that how to check that the user id is already exists in the user table or not when user trying to register, i am using sql server 2000?
Share
Based on the code in your comment, I’d say what you need is a good introductory tutorial on how to query data using ADO.NET, if anyone can recommend one.
First of all, you can’t just use “username.Text” in your query, the SQL Server knows nothing about your ASP.NET page and it’s “username” TextBox.
You need to pass a parameter into your SqlCommand (don’t ever build a string like “select * from tbl_userlogin where User_id=” + username.Text, google for “sql injection attack” if you want to know why), like this:
Then, you need to actually execute the command and get an SqlDataReader back from it. You can’t just refer to fields from the database in your C# code, that’s why you’re getting the CS0103 compile error.
Now, your SqlDataReader has the results from the query. Since all you care about is whether or not it found something, you can use the HasRows property to check if it returned anything.
Read up on SqlDataReader – http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.aspx – to learn how to actually access the results if you need to.