Reputation: 77
When I click the button, only my first query gets executed. The second one insert into afspraken (behandeling)
doesn't execute. Anybody knows why?
private void button1_Click(object sender, EventArgs e)
{
string insertStatement = "INSERT INTO Afspraken (Afspraakdatum) VALUES ('" + textBox23.Text + "');";
string insertStatement1 = "INSERT INTO Afspraken (Behandeling) VALUES ('" + textBox21.Text + "');";
OleDbCommand insertCommand = new OleDbCommand(insertStatement, connection);
OleDbCommand insertCommand1 = new OleDbCommand(insertStatement1, connection);
connection.Open();
try
{
int count = insertCommand.ExecuteNonQuery();
}
catch (OleDbException ex)
{
}
finally
{
connection.Close();
textBox23.Clear();
textBox21.Clear();
MessageBox.Show("Uw afspraak is gemaakt!");
}
}
Upvotes: 0
Views: 58
Reputation: 14967
As I saw in your comments on another answer, I believe this solution would work best for you:
string insertStatement = "INSERT INTO Afspraken (Afspraakdatum, Behandeling) VALUES ('" + textBox23.Text + "', '" + textBox21.Text + "');");
OleDbCommand insertCommand = new OleDbCommand(insertStatement, connection);
But remember that this code is unsafe, you should use prepared statements instead.
Upvotes: 1
Reputation: 210
You're creating insertCommand1
, but you're never executing it. You're only executing insertCommand
(in the single line inside your try
block).
Upvotes: 2