maybe you can try this code
private void button1_Click(object sender, EventArgs e)
{
try
{
cmd = new OleDbCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "INSERT INTO userinfo (FirstName, LastName, Age, Address, Course)" + "VALUES (@First_Name, @Last_Name, @Age, @Address, @Course)";
cmd.Parameters.AddWithValue("@First_Name", textBox1.Text);
cmd.Parameters.AddWithValue("@Last_Name", textBox2.Text);
cmd.Parameters.AddWithValue("@Age", textBox3.Text);
cmd.Parameters.AddWithValue("@Address", textBox5.Text);
cmd.Parameters.AddWithValue("@Course", textBox5.Text);
cmd.Connection = conn;
conn.Open();
clear();
cmd.ExecuteNonQuery();
{
MessageBox.Show("Data Added!");
conn.Close();
}
dataholder();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
if you’ll declare parameters. you may have to used them in a way. Hope it helps 🙂
1
solved i cant insert data in ms access database through textbox [closed]