I was trying to insert values into an Access database using a parameterized query:
private void button1_Click(object sender, EventArgs e)
{
if (validationcontrol())
{
MessageBox.Show(cmbjobcode.SelectedValue.ToString());
OleDbConnection oleDbConnection1 = new System.Data.OleDb.OleDbConnection(connString);
oleDbConnection1.Open();
OleDbCommand oleDbCommand1 = new System.Data.OleDb.OleDbCommand("INSERT INTO quotationmastertable (quotationcode ,jobcode , jobpk , sillabordercharges , battabordercharges , driverpayment , rent , extra , total , discount , remark ,amount ) Values (?,?,?,?,?,?,?,?,?,?,?,?) ", oleDbConnection1);
oleDbCommand1.Parameters.Add(txtquotationno.Text);
oleDbCommand1.Parameters.Add(cmbjobcode.Text);
oleDbCommand1.Parameters.Add(cmbjobcode.SelectedValue);
oleDbCommand1.Parameters.Add(int.Parse(txtsilabordercharges.Text));
oleDbCommand1.Parameters.Add(int.Parse(txtbattacharges.Text));
oleDbCommand1.Parameters.Add(int.Parse(txtdriverpayment.Text));
oleDbCommand1.Parameters.Add(int.Parse(txtrent.Text));
oleDbCommand1.Parameters.Add(int.Parse(txtextra.Text));
oleDbCommand1.Parameters.Add(int.Parse(txttotal.Text));
oleDbCommand1.Parameters.Add(int.Parse(txtdiscount.Text));
oleDbCommand1.Parameters.Add(txtremark.Text);
oleDbCommand1.Parameters.Add(int.Parse(txtamount.Text));
oleDbCommand1.CommandType = CommandType.Text;
oleDbCommand1.ExecuteNonQuery();
oleDbConnection1.Close();
MessageBox.Show(txtquotationno.Text);
}
}
but I am getting an exception at the first line itself:
oleDbCommand1.Parameters.Add(txtquotationno.Text);
The exception is
The OleDbParameterCollection only accepts non-null OleDbParameter type objects, not String objects.
I am new to programming; can anyone help in pointing out my mistakes?