Try:
cmd = new SqlCommand("select role from temp where (emp_id='" + txtUserId.Text + "' and paswrd='" + txtPwd.Text + "')",cn);
SqlDataReader reader = cmd.ExecuteReader().Read().ToString();
if (reader.Read())
{
Console.Write((string) reader["role"]);
}
Or, better, use parametrised queries and stop people destroying your database with SQL Injection:
cmd = new SqlCommand("select role from temp where (emp_id=@ID and paswrd=@PW)",cn);
cmd.Parameteres.AddWithValue("@ID", txtUserId.Text);
cmd.Parameteres.AddWithValue("@PW", txtPwd.Text);
SqlDataReader reader = cmd.ExecuteReader().Read().ToString();
if (reader.Read())
{
Console.Write((string) reader["role"]);
}
Even better, don't ever store passwords in straight text! There is a Tip here that explains that:
Password Storage: How to do it.[
^]
"can u provaide the solution through SqlDataAdaptor..
thanks"
What did your last slave die of?
using (SqlConnection connection = new SqlConnection(strConnect))
{
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand("SELECT role FROM temp WHERE emp_id=@ID AND paswrd=@PW", connection);
da.SelectCommand.Parameters.AddWithValue("@ID", txtUserId.Text);
da.SelectCommand.Parameters.AddWithValue("@PW", txtPwd.Text);
DataTable dt = new DataTable();
da.Fill(dt);
}