列名id无效的错误
public void bind()
{
string id = Session["user_id"].ToString();
string sqlstr = "select * from Users,Roles where Users.user_id = Roles.user_id and Users.user_id = id";
sqlcon = new SqlConnection(strCon);
SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
DataSet myds = new DataSet();
sqlcon.Open();
myda.Fill(myds, "table"); 此行出现列名id无效的错误
GridView1.DataSource = myds;
GridView1.DataKeyNames = new string[] { "user_id" };//主键
GridView1.DataBind();
sqlcon.Close();
}
------解决方案--------------------
SQL查询字符串写错了,以后记得细心~~
C# code
string sqlstr = "select * from Users,Roles where Users.user_id = Roles.user_id and Users.user_id = id";
改为:
string sqlstr =string.Format( "select * from Users,Roles where Users.user_id = Roles.user_id and Users.user_id = {0} ", id);