C#datagridview绑定access,传参失败
stringstrPath=@"Provider=Microsoft.ACE.OLEDB.12.0;PersistSecurityInfo=False;DataSourc...
string strPath = @"Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info=False;Data Source=|DataDirectory|\教务管理.accdb";
OleDbConnection con = new OleDbConnection(strPath);
con.Open();
string sql = "select 课程名,课程号,学分,课程属性,考试类型,替代课程号,成绩 from 成绩 where 学号=@username";
OleDbCommand cmd = new OleDbCommand(sql,con); //cmd.CommandText = sql;//cmd = con.CreateCommand();
cmd.Parameters.AddWithValue("@username", uname);
OleDbDataAdapter ad = new OleDbDataAdapter(sql, con);
DataTable dt = new DataTable();
ad.Fill(dt);
dataGridView1.DataSource = dt.DefaultView;
con.Close();
其他都对的,把Where去掉就可以,应该是@username没赋值成功,求解,不知道怎么弄 展开
OleDbConnection con = new OleDbConnection(strPath);
con.Open();
string sql = "select 课程名,课程号,学分,课程属性,考试类型,替代课程号,成绩 from 成绩 where 学号=@username";
OleDbCommand cmd = new OleDbCommand(sql,con); //cmd.CommandText = sql;//cmd = con.CreateCommand();
cmd.Parameters.AddWithValue("@username", uname);
OleDbDataAdapter ad = new OleDbDataAdapter(sql, con);
DataTable dt = new DataTable();
ad.Fill(dt);
dataGridView1.DataSource = dt.DefaultView;
con.Close();
其他都对的,把Where去掉就可以,应该是@username没赋值成功,求解,不知道怎么弄 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询