var a = "1";
var b = "2";
var c = "3";
var name = authResult.ExtraData["email"];
string
connetionString = null;
SqlConnection cnn;
SqlCommand cmd;
string sql = null;
SqlDataReader reader;
connetionString = "Data Source = dj0043\\sqlexpress; Initial Catalog = XXXX; Integrated Security = True";
sql = "Select EmployeeRoles.RoleId From EmployeeList Inner Join EmployeeRoles on EmployeeList.EmployeeId =EmployeeRoles.EmployeeId Where EmailId = name";
cnn = new SqlConnection(connetionString);
try
{
cnn.Open();
cmd = new SqlCommand(sql, cnn);
reader = cmd.ExecuteReader();
while (reader.Read())
{
if (reader == a)
{
return Redirect(Url.Action("Employee", "Home"));
}
else if (sql == b)
{
return Redirect(Url.Action("Index", "Home"));
}
else if (sql == c)
{
return Redirect(Url.Action("Index", "Home"));
}
}
reader.Close();
cmd.Dispose();
cnn.Close();
在这种情况下,如果任何用户的ID为1,该用户名将被重定向到该页面,反之亦然尽管任何人都可以告诉我如何使sql reader在这种情况下工作
谢谢
这是您应该采取的方式
if ((int)reader["RoleId"] == 1)
{
return Redirect(Url.Action("Employee", "Home"));
}
else if ((int)reader["RoleId"] == 2)
{
return Redirect(Url.Action("Index", "Home"));
}
else if ((int)reader["RoleId"] == 3)
{
return Redirect(Url.Action("Index", "Home"));
}