从sql server库里查询出选定条件的记录,条件是session变量
Session["UserName"]=ST_read[0].ToString();
..........
sql="select * from user where name='Session["UserName"]'"
这句应该怎么写呢?
请前辈们指教一下。。。。
...全文
23820打赏收藏
有条件查询的SQL语句,条件是session变量
从sql server库里查询出选定条件的记录,条件是session变量 Session["UserName"]=ST_read[0].ToString(); .......... sql="select * from user where name='Session["UserName"]'" 这句应该怎么写呢? 请前辈们指教一下。。。。
sql="select * from [user] where name = @name";
SqlConnection cn = new SqlConnection(@"server=.\sqlexpress;uid=sa;pwd=;database=yourdatabase");
SqlCommand cmd = new SqlCommand(sql, cn);
//前面一定要判断Session["UserName"]不为null
cmd.Parameters.AddWithValue("@name", Session["UserName"].ToString());