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.
Shouldn't
cmd.Parameters.AddWithValue(@"Nam", textBox1.Text);
Be:
cmd.Parameters.AddWithValue("@Nam", textBox1.Text);
And so on for the other parameters?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With