Actually im trying to insert as well as update data into datagridview at run time for that i have written one code but while executing it give me
Data type mismatch in criteria expression
exception in cmd
.ExecuteNonQuery();
line
my accdb table structure is like below
Field Datatype
Account-- Memo
AccountNumber--Number
Date--Date/Time
Description--Memo
Post_Ref--Memo
Debit--Number
Credit--Number
Balance--Number
What I have tried:
my code:
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
account = dataGridView1.Rows[e.RowIndex].Cells["AccountNumber"].Value.ToString();
if (account == "")
{
account1 = 0;
}
else
{
account1 = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["AccountNumber"].Value.ToString());
}
if (account1 == 0)
{
OleDbCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into Ledger values('" + dataGridView1.Rows[e.RowIndex].Cells["Account"].Value.ToString() + "','" + dataGridView1.Rows[e.RowIndex].Cells["AccountNumber"].Value.ToString() + "','" + dataGridView1.Rows[e.RowIndex].Cells["Date"].Value.ToString() + "','" + dataGridView1.Rows[e.RowIndex].Cells["Description"].Value.ToString() + "','" + dataGridView1.Rows[e.RowIndex].Cells["Post_Ref"].Value.ToString() + "','" + dataGridView1.Rows[e.RowIndex].Cells["Debit"].Value.ToString() + "','" + dataGridView1.Rows[e.RowIndex].Cells["Credit"].Value.ToString() + "','" + dataGridView1.Rows[e.RowIndex].Cells["Balance"] + "')";
cmd.ExecuteNonQuery();--> exception coming this line
Load_data();
}