0
我有這個工作查詢:C#試圖插入Access,代碼工作,但如果我添加兩個新參數它不?
"Insert INTO ACTB (ID, FirstName, LastName, GrossIncome, LessTNT, TaxableIncomeCE, TaxableIncomePE, GrossTaxableIncome, LessTE, LessPPH, NetTax, TaxDue, HeldTaxCE, HeldTaxPE, TotalTax, TIN) " +
"VALUES(@ID, @First, @Last, @Gross, @LessTNT, @TCI, @ADDTI, @GTI, @LessTE, @LessPPH, @LessNTI, @TD, @TWCE, @TWPE, @TATW, @TIN)";
不知道如何格式化更好。無論如何,這與整個命令執行的事情一起工作。現在我已經更新了我的程序的要求,並添加了兩個額外的字段,例如From和To。
"Insert INTO ACTB (ID, FirstName, LastName, GrossIncome, LessTNT, TaxableIncomeCE, TaxableIncomePE, GrossTaxableIncome, LessTE, LessPPH, NetTax, TaxDue, HeldTaxCE, HeldTaxPE, TotalTax, TIN, From, To) " +
"VALUES(@ID, @First, @Last, @Gross, @LessTNT, @TCI, @ADDTI, @GTI, @LessTE, @LessPPH, @LessNTI, @TD, @TWCE, @TWPE, @TATW, @TIN, @From, @To)";
而現在它返回一個非常無益的錯誤:INSERT INTO語法錯誤。這就是它說的。
下面是您分析的其餘代碼。如果我將它從中刪除,它可以很好地工作。
OleDbConnection Dbcon = new OleDbConnection(Con);
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = "Insert INTO ACTB (ID, FirstName, LastName, GrossIncome, LessTNT, TaxableIncomeCE, TaxableIncomePE, GrossTaxableIncome, LessTE, LessPPH, NetTax, TaxDue, HeldTaxCE, HeldTaxPE, TotalTax, TIN, From, To) " +
"VALUES(@ID, @First, @Last, @Gross, @LessTNT, @TCI, @ADDTI, @GTI, @LessTE, @LessPPH, @LessNTI, @TD, @TWCE, @TWPE, @TATW, @TIN, @From, @To)";
cmd.Parameters.AddWithValue("@ID", txtID.Text);
cmd.Parameters.AddWithValue("@First", txtFirst.Text);
cmd.Parameters.AddWithValue("@Last", txtLast.Text);
cmd.Parameters.AddWithValue("@Gross", Convert.ToDouble(txtGross.Text));
cmd.Parameters.AddWithValue("@LessTNT", Convert.ToDouble(txtLessTNT.Text));
cmd.Parameters.AddWithValue("@TCI", Convert.ToDouble(txtTCI.Text));
cmd.Parameters.AddWithValue("@ADDTI", Convert.ToDouble(txtADDTI.Text));
cmd.Parameters.AddWithValue("@GTI", Convert.ToDouble(txtGTI.Text));
cmd.Parameters.AddWithValue("@LessTE", Convert.ToDouble(txtLessTE.Text));
cmd.Parameters.AddWithValue("@LessPPH", Convert.ToDouble(txtLessPPH.Text));
cmd.Parameters.AddWithValue("@LessNTI", Convert.ToDouble(txtLessNTI.Text));
cmd.Parameters.AddWithValue("@TD", Convert.ToDouble(txtTD.Text));
cmd.Parameters.AddWithValue("@TWCE", Convert.ToDouble(txtTWCE.Text));
cmd.Parameters.AddWithValue("@TWPE", Convert.ToDouble(txtTWPE.Text));
cmd.Parameters.AddWithValue("@TATW", Convert.ToDouble(txtTATW.Text));
cmd.Parameters.AddWithValue("@TIN", txtTIN.Text);
cmd.Parameters.AddWithValue("@From", txtFrom.Text);
cmd.Parameters.AddWithValue("@To", txtTo.Text);
Dbcon.Open();
cmd.Connection = Dbcon;
try
{
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
我已經雙重檢查了數據源視圖,而且我的Access數據庫確實是更新的數據庫,所以這些字段應該存在!
這工作,謝謝!我一直忘記保留字,包括SQL和C#! – Aroueterra