使用参数查旬,结果绑定到gridview有问题!!!
由于考虑到安全性,使用参数查询。
string cmdCode = "select * from KHGL_Customer where cCusCode=@cCusCode ";
OleDbDataAdapter daCode = new OleDbDataAdapter(cmdCode, myconnection);
OleDbCommand mycommand = new OleDbCommand(cmdCode, myconnection);
mycommand.Parameters.Add(new OleDbParameter( "@cCusCode ", OleDbType.VarChar, 20));
mycommand.Parameters[ "@cCusCode "].Value = txtSearch.Text;
myconnection.Open();
DataSet dsCode = new DataSet();
daCode.Fill(dsCode, "KHGL_Customer ");
GridView1.DataSource = dsCode;
GridView1.DataBind();
myconnection.Close();
这一句daCode.Fill(dsCode, "KHGL_Customer ");提示:至少一个参数没有被指定值。如果不使用参数就一点问题也没有。怎么解决???
------解决方案--------------------string cmdCode = "select * from KHGL_Customer where cCusCode=@cCusCode ";
OleDbCommand mycommand = new OleDbCommand(cmdCode, myconnection);
mycommand.Parameters.Add(new OleDbParameter( "@cCusCode ", OleDbType.VarChar, 20));
mycommand.Parameters[ "@cCusCode "].Value = txtSearch.Text;
OleDbDataAdapter daCode = new OleDbDataAdapter(mycommand);//这里
myconnection.Open();
DataSet dsCode = new DataSet();
daCode.Fill(dsCode, "KHGL_Customer ");
GridView1.DataSource = dsCode;
GridView1.DataBind();
myconnection.Close();