看起来像是ado.net的基础问题,
string sqlCommand = "SELECT loginCount FROM talbe WHERE userName=@userName";
var dt = new DataTable();
using (var conn = new SqlConnection("connction string here"))
{
var cmd = new SqlCommand(sqlCommand);
//从session中取出userName,作为sql语句的参数
cmd.Parameters.Add(new SqlParameter("userName", Session["userName"].ToString()));
var adt = new SqlDataAdapter(cmd);
adt.Fill(dt);
}
//这就是从数据库中读出的数据
var loginCount = (int)dt.Rows[0][0];
//获得用户名
string username=session["username"].tostring();
//查询logincount字段
string sql="select logincount from table where username="+username;
int logincount=db.GetintScalar(sql);
//赋值给变量
int bianliang=logincount;