簡體   English   中英

更新語句不會更新表

[英]Update Statement will not update table

我正在嘗試更新MS Access表中的供應商記錄,這是DA層中的代碼:

更新供應商的方法

public static void updateVendor(Vendor aVendor)
{
    try
    {
        String sSQLCommand = "UPDATE Vendor SET VendorID = '" + aVendor.VendorId + "', VendorName = '" + aVendor.Name 
                            + "', AddressNo = '" + aVendor.AddressNo + "', Address = '" + aVendor.Address + "', City = '" 
                            + aVendor.City + "', State = '" + aVendor.State + "', ZipCode = '" + aVendor.Zipcode + "', PhoneNumber = '" 
                            + aVendor.PhoneNumber + "' WHERE VendorID = '" + aVendor.VendorId + "'";

        // Create the command object
        if (aConnection.State == ConnectionState.Closed)
            aConnection.Open();

        OleDbCommand cmd = aConnection.CreateCommand();
        cmd.CommandText = sSQLCommand;
        // Execute the SQL command
        cmd.ExecuteNonQuery();
        aConnection.Close();
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.ToString());
    }
}

我沒有收到任何類型的錯誤,但是它不會更新表,所以我不確定它有什么問題,您是否看到任何錯誤?

Daniel,如果查詢正在執行而沒有任何錯誤,並且問題在於沒有記錄被更新,那么請檢查以下數據:

  • VendorID字段是文本字段,因此,如果該列中的值前面有空格,那么您的查詢將不會更新任何內容,但會成功執行。

這是可能的,因為訪問不會刪除文本中的前面的空格。

暫無
暫無

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

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