The sloppy way would be to grab this within a
WHILE
loop in some variation of this
if (rd.HasRows) {
while (rs.Read()) {
string RedirectURL = rd["ColumnName"];
}
}
Response.Redirect(RedirectURL);
I would probably redo this to be something more like this; you only need one value from one row so
ExecuteScalar
would be much more efficient. And what happens if they are in neither group? I threw in an Exception for that.
You may need to fix some typos as I do not have an IDE checking my typing
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand("SELECT Departmet FROM [dbo].[PB_Register] WHERE pb_Email= @Login_Email AND pb_Password=@Login_Password", con);
cmd.Parameters.AddWithValue("@Login_Email",Login_Email.Text);
cmd.Parameters.AddWithValue("@Login_Password", Login_Password.Text);
Session["Username"] = Login_Email.Text;
con.Open();
var DepartmentName = cmd.ExecuteScalar();
if (DepartmentName != null) {
switch(DepartmentName.ToSting()) {
case "EPIP" : Response.Redirect("UPLOAD.aspx"); break
case "Waste" : Response.Redirect("EMAIL_FILE.aspx"); break
default: throw new ArgumentOutOfRangeException("Department", "The department does not have an assigned path"); break
}
} else {
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Username or Password incorrect');", true);
}