Generally we need to validate while designing a login page that entered username exists in our database or not, below is the codesnippet to do that.
string strSql = ""select AutoId from userslogin u where " +
"u.UserName = @userName order by username";
SqlParameter[] prms = new SqlParameter[1];
prms[0] = new SqlParameter("@userName", SqlDbType.Varchar, 50);
prms[0].Value = userName; // passed as input to the method
object obj = base.ExecuteScalar(ConnStr, CommandType.Text, strSql); // here ConnStr is the connection string of your database.
if (obj != null)
{
return 0; // user exists in the database
}
else
{
// user doesn't exists in the database, proceed with inserting the record
}
Hope this helps