当我运行以下代码时,我收到错误
没有给出一个或多个必需参数的值。
有人可以建议为什么会这样吗?
namespace ATMPROJECT
{
public partial class pin : Form
{
public pin()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OleDbConnection con= new OleDbConnection ();
OleDbCommand cmd;
DataSet ds;
OleDbDataAdapter da;
OleDbDataReader dr = null;
string i;
con = new OleDbConnection ( "Provider = Microsoft.ACE.OLEDB.12.0; Data Source =C:\\Users\\RELIABLE TRADING CO\\Documents\\atm.accdb ");
con.Open();
if (textBox1.Text == "")
{
label1.Text = ("PLZ ENTER YOUR PIN FIRST");
}
else
{
ds = new DataSet();
i = @"SELECT * from atm WHERE pin= ?";
cmd = new OleDbCommand(i,con);
cmd.Parameters.Add("@pin",OleDbType.VarChar).Value = textBox1 .Text;
da = new OleDbDataAdapter(cmd);
MessageBox.Show("done");
da.Fill(ds);
dataGridView1.DataSource = ds;
// generates error (No value given for one or more required parameters.)
答案 0 :(得分:0)
该错误表示您的atm
表没有名为pin
的字段。
此外,您可能必须在DataSource中指定表:
dataGridView1.DataSource = ds.Tables[0];