string strConnect = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=record.accdb";
using (OleDbConnection con = new OleDbConnection(strConnect))
{
con.Open();
using (OleDbCommand cmd = new OleDbCommand("insert into Industry(cName,Amount,amt_type,cheqno,bankname,branchname,tDate) values(@cname,@amount,@amt_type,@chqnum,@bname,@bchname,@tdate)", con))
{
cmd.Parameters.AddWithValue("@cname", name_txt.Text);
cmd.Parameters.AddWithValue("@amount", Convert.ToDouble(amount_txt.Text));
cmd.Parameters.AddWithValue("@amt_type", amt);
cmd.Parameters.AddWithValue("@chqnum", cheque_txt.Text);
cmd.Parameters.AddWithValue("@bname", bank_txt.Text);
cmd.Parameters.AddWithValue("@bchname", branch_txt.Text);
cmd.Parameters.AddWithValue("@tdate", dateTimePicker1.Value.ToShortDateString());
cmd.ExecuteNonQuery();
}
con.Close();
I have a error saying An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: Data type mismatch in criteria expression. What could be the possible reason for that and error is at line cmd.ExecuteNonQuery();.
There are two radio buttons which takes input text on changed event i noticed that on checking cheque and filling all the details of the form it works but when i check on cash field and leave some fields blank it throws an exception any help would be appreciated.
dateTimePicker1.Value.ToShortDateString()
might be returning something that isn't compatible, try with justdateTimePicker1.Value
(of course it could be one of the other values/fields). - user2864740