Reputation: 2499
I am created database using microsoft access. From this database i can only read the data and can't add new entries to it,
I use below code to insert data
cmd = new OleDbCommand("insert into [Accountstbl] values(" + textBox1.Text +
",' " + textBox6.Text + " ',' " + textBox3.Text + " ')", cn);
But when I click ok, the form just turns to not responding and didn't insert any data in the database, I know my path is correct because I can read the data,
can you give me a guide about this? can't find anything :( thanks,
Upvotes: 0
Views: 58
Reputation: 6079
Missing single quote for first textbox(textBox1.Text)?
Try Below one
cmd = new OleDbCommand("insert into [Accountstbl] values('" + textBox1.Text +
"',' " + textBox6.Text + " ',' " + textBox3.Text + " ')", cn);
And try to put the below code where you have a doubt that its going wrong
try
{
//Insertion code here, .............Query,ExcuteNonQuery,.....etc
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());//You will get here what problem is there.....
}
Upvotes: 1
Reputation: 1276
Try:
cmd = new OleDbCommand("insert into [Accountstbl] (field1, field2, field3) values(" + textBox1.Text + ",' " + textBox6.Text + " ',' " + textBox3.Text + " ')", cn);
Replace field# with the ones in your database.
Upvotes: 0