page to query the database to see if this id is already taken. My logic is that perform an sql select query, then if the result set is empty (null value), then the id is valid (as nobody is using it yet); if not, the id is already taken by someone.
Any idea how can i evaluate the result set? I have tried:
++++++++++++
string sqlSelect = "SELECT * FROM member WHERE usrid= '"+ IDValue + "'";
SqlDataAdapter adp=new SqlDataAdapter(sqlSelect,"server=aaaa;database=db;User ID=id123;pwd=123123");
DataSet ds=new DataSet();
adp.Fill(ds,"member");
if (ds==null)
{
value.IsValid = true;
}
else
{
value.IsValid = false;
}
+++++++++++++
which does not work and tells "the id is taken" always. Obviously the dataset is never empty even though it has no records at all...
any help please? if i have done sth obviously wrong please point out and any other methods please?
Thanks very muchI don't think you should use the DataSet if you only will query the datasource to let you know if the Id is taken or not. Use the ExecuteScalar method of the SqlCommand class and also use parameters to avoid Sql-injection.
cheers for that! solved now
No comments:
Post a Comment