在C#中如何在后台代码里面的select中取值
using(SqlConnectionconn=newSqlConnection(WebConfigurationManager.ConnectionStrings["O...
using (SqlConnection conn= new SqlConnection(WebConfigurationManager.ConnectionStrings["OAConnectionString"].ConnectionString))
{
conn.Open();
SqlCommand command = new SqlCommand("SELECT BasicInfo.Power FROM BasicInfo WHERE BasicInfo.Username=@Username and BasicInfo.PW=@PW", conn);
command.CommandType = CommandType.Text;
command.Parameters.AddWithValue("@Username", username);
command.Parameters.AddWithValue("@PW", PW);
SqlDataReader reader = command.ExecuteReader();
这是代码段 我想取得select语句Power的结果 并把结果保留下来作为后续代码的验证条件 展开
{
conn.Open();
SqlCommand command = new SqlCommand("SELECT BasicInfo.Power FROM BasicInfo WHERE BasicInfo.Username=@Username and BasicInfo.PW=@PW", conn);
command.CommandType = CommandType.Text;
command.Parameters.AddWithValue("@Username", username);
command.Parameters.AddWithValue("@PW", PW);
SqlDataReader reader = command.ExecuteReader();
这是代码段 我想取得select语句Power的结果 并把结果保留下来作为后续代码的验证条件 展开
1个回答
展开全部
string power;
using (SqlConnection conn= new SqlConnection(WebConfigurationManager.ConnectionStrings["OAConnectionString"].ConnectionString))
{
conn.Open();
SqlCommand command = new SqlCommand("SELECT BasicInfo.Power FROM BasicInfo WHERE BasicInfo.Username=@Username and BasicInfo.PW=@PW", conn);
command.CommandType = CommandType.Text;
command.Parameters.AddWithValue("@Username", username);
command.Parameters.AddWithValue("@PW", PW);
power = command.ExecuteScalar().ToString(); //保存值
}
追问
不好意思 这里的power我忘记说是int类型 如果是int类型如何修改呢
追答
int power;
... ...
power = Convert.ToInt32(command.ExecuteScalar());
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询