2017-10-05 6 views
-1
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(); 
+2

Bienvenue dans Stack Overflow. Veuillez lire [ask] et comment créer [mcve]. –

Répondre

2

La transaction est un mot-clé SQL! Vous devez le mettre entre crochets:

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

Fait: Désolé, il m'a fallu 5 min pour obtenir la bonne réponse – Whismer

+0

C'est beaucoup mieux, nous prenons tous le temps de nous habituer à ce formatage –