string type = "Cash";
string type1 = "Card";
if (radioButton1.Checked)
{
myDB.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter(@"SELECT * FROM Transaction", myDB);
adapter.Fill(dt);
OleDbCommand cmd = new OleDbCommand(@"INSERT INTO Transaction(Type, Amount) Values ('" + type + "', " + label3.Text + ")", myDB);
cmd.ExecuteNonQuery();
}
else if(radioButton2.Checked)
{
OleDbDataAdapter adapter = new OleDbDataAdapter(@"SELECT * FROM Transaction", myDB);
adapter.Fill(dt);
OleDbCommand cmd = new OleDbCommand(@"INSERT INTO Transaction(Type, Amount) Values ('" + type1 + "', " + label3.Text + ")", myDB);
cmd.ExecuteNonQuery();
}
myDB.Close();
答案 0 :(得分:2)
Transaction是一个SQL关键字!你需要把它放在方括号中:
string type = "Cash";
string type1 = "Card";
if (radioButton1.Checked)
{
myDB.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter(@"SELECT * FROM [Transaction]", myDB);
adapter.Fill(dt);
OleDbCommand cmd = new OleDbCommand(@"INSERT INTO [Transaction](Type, Amount) Values ('" + type + "', " + label3.Text + ")", myDB);
cmd.ExecuteNonQuery();
}
else if(radioButton2.Checked)
{
OleDbDataAdapter adapter = new OleDbDataAdapter(@"SELECT * FROM [Transaction]", myDB);
adapter.Fill(dt);
OleDbCommand cmd = new OleDbCommand(@"INSERT INTO [Transaction](Type, Amount) Values ('" + type1 + "', " + label3.Text + ")", myDB);
cmd.ExecuteNonQuery();
}
myDB.Close();