I have the following code which tries to store e values form 3 textboxes into a MS Access 2007 database.
string ConnString = (@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\\dxs.accdb");
string SqlString = "Insert Into tests( [Nam], [add], [phone]) Values (?,?,?)";
using (OleDbConnection conn = new OleDbConnection(ConnString))
{
using (OleDbCommand cmd = new OleDbCommand(SqlString, conn))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue(@"Nam", textBox1.Text);
cmd.Parameters.AddWithValue(@"add", textBox2.Text);
cmd.Parameters.AddWithValue(@"phone",textBox3.Text);
conn.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("entered");
}
}
But even though the code is correct after entering values nothing is being stored in table.
ExecuteNonQuery, it returns the number of rows changed in the database. If it's zero then you know something is up.