i hv 3 different user,user selection is based on radiobuttonlist and then login button,but im having error that "use of unassigned local variable 'sql'.I couldnt figure out the mistake.do help me :)
protected void btn_Login_Click(object sender, EventArgs e)
{
string sql;
if (btn_user.SelectedItem.Text == "Admin")
{
sql = "Select * from Admin where Username='" + txt_Luser.Text + "' and Password='" + txt_Lpass.Text + "'";
}
else if (btn_user.SelectedItem.Text == "Agent")
{
sql = "Select * from Agent where Username='" + txt_Luser.Text + "' and Password='" + txt_Lpass.Text + "'";
}
else if (btn_user.SelectedItem.Text == "Student")
{
sql = "Select * from Student where Username='" + txt_Luser.Text + "' and Password='" + txt_Lpass.Text + "'";
}
conn.open;
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.CommandType = CommandType.Text;
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.HasRows)
{
Session["User"] = txt_Luser.Text;
Response.Redirect("Home.aspx");
}
else
{
txt_Luser.Text = string.Empty;
lbl_msg.Text = "Please enter correct Username and Password";
}
conn.Close();
}