When I run the following code I receive the error
No value given for one or more required parameters.
Can anyone suggest why that might be?
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.)
That error indicates your atm
table does not have a field called pin
.
Also, you probably have to specify the table in the DataSource:
dataGridView1.DataSource = ds.Tables[0];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.