簡體   English   中英

OleDbException (x80040E14):Insert into 語句中的語法錯誤

[英]OleDbException (x80040E14): Syntax error in Insert into statement

任何人都可以幫助解決這個問題嗎? 我嘗試了很多不同的事情,但仍然出現此錯誤。 錯誤指向 cmd.ExecuteNonQuery() 行。 我已經檢查了插入字符串一百萬次,但我看不出有什么問題。 謝謝!

OleDbConnection myConnection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + targetPath);                        
try
{
    for (int i = 0; i < listOfDBTables.Count; i++)
    {
        for (int j = 1; j < listOfDBTables[i].Rows.Count; j++)
        //Don't include the header
        {
            OleDbCommand cmd = new OleDbCommand("INSERT INTO POP(Global Customer, Sold To #, Material #, Material Description, Customer ID, Customer Name, City, State, Country, Market Code, Unit Cost, Invoice Date, [Month], Quantity, UoM, KG, [Year]) Values (@globCust,@soldToNum,@matNum,@matDesc,@custID,@custName,@city,@state,@country,@mktCode,@cost,@invDate,@month,@quantity,@uom,@kg,@year)", myConnection);

            cmd.Parameters.AddWithValue("@globCust", listOfDBTables[i].Rows[j][0].ToString());
            cmd.Parameters.AddWithValue("@soldToNum", listOfDBTables[i].Rows[j][1].ToString());
            cmd.Parameters.AddWithValue("@matNum", listOfDBTables[i].Rows[j][2].ToString());
            cmd.Parameters.AddWithValue("@matDesc", listOfDBTables[i].Rows[j][3].ToString());
            cmd.Parameters.AddWithValue("@custID", listOfDBTables[i].Rows[j][4].ToString());
            cmd.Parameters.AddWithValue("@custName", listOfDBTables[i].Rows[j][5].ToString());
            cmd.Parameters.AddWithValue("@city", listOfDBTables[i].Rows[j][6].ToString());
            cmd.Parameters.AddWithValue("@state", listOfDBTables[i].Rows[j][7].ToString());
            cmd.Parameters.AddWithValue("@country", listOfDBTables[i].Rows[j][8].ToString());
            cmd.Parameters.AddWithValue("@mktCode", listOfDBTables[i].Rows[j][9].ToString());
            cmd.Parameters.AddWithValue("@cost", listOfDBTables[i].Rows[j][10].ToString());
            cmd.Parameters.AddWithValue("@invDate", listOfDBTables[i].Rows[j][11].ToString());
            cmd.Parameters.AddWithValue("@month", listOfDBTables[i].Rows[j][12].ToString());
            cmd.Parameters.AddWithValue("@quantity", listOfDBTables[i].Rows[j][13].ToString());
            cmd.Parameters.AddWithValue("@uom", listOfDBTables[i].Rows[j][14].ToString());
            cmd.Parameters.AddWithValue("@kg", listOfDBTables[i].Rows[j][15].ToString());
            cmd.Parameters.AddWithValue("@year", listOfDBTables[i].Rows[j][16].ToString());

            myConnection.Open();
            cmd.ExecuteNonQuery();
        }
    }
}
catch(Exception ex)
{
    MessageBox.Show(ex.ToString());
}
finally
{
    myConnection.Close();
}

你應該把你的列放在 [] 中,例如讓它 [Sold To #] 而不是 Sold To #

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM