从sql server库里查询出选定条件的记录,条件是session变量
Session["UserName"]=ST_read[0].ToString();
..........
sql="select * from user where name='Session["UserName"]'"
这句应该怎么写呢?请前辈们指教一下。
Session["UserName"]=ST_read[0].ToString();
..........
sql="select * from user where name='Session["UserName"]'"
这句应该怎么写呢?请前辈们指教一下。
sql="select * from user where name='"+Session["UserName"]+"'" 这样拼接就可以了
sql="select * from user where name='"+Session["UserName"]+"'"
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());