【问题标题】:Update query works for all columns except one更新查询适用于除一列之外的所有列
【发布时间】:2012-10-19 10:05:12
【问题描述】:

我的 .xsd 文件中有如下更新查询:

UPDATE Factors 
SET    CodeFactor = @CodeFactor, Date = @Date, MobileNumber = @MobileNumber, 
       Description= @Description, TotalPrice = @TotalPrice, 
       ShouldPayPrice = @ShouldPayPrice 
       WHERE ID = @Original_ID; 
SELECT   ID, CodeFactor, Date, PersonName, MobileNumber, Description, TotalPrice, 
         ShouldPayPrice, PaidPrice, Settlement, Kind 
FROM     Factors 
WHERE    ID = @Original_ID
ORDER BY Date DESC;

我以如下形式使用它:

Fact.UpdateQuery(txtShomareFactor.Text.Trim(), fdpDate.Text.Trim(),
                 txtMobile.Text.Trim(), txtSharheKharid.Text,
                 Convert.ToInt64(txtJameKol.Text.Replace(",", "").Trim()),
                 Convert.ToInt64(txtMablagheGhabelePardakht.Text.Replace(",", "").Trim()), 
                 IDFactorTOShowDetails);

它会更新除描述列之外的所有列!

【问题讨论】:

  • 尝试在 [] 中包含字段名称,例如 [MobileNumber] = @MobileNumber
  • 我做到了,但它不再起作用了。 :( 还有其他建议吗?
  • @description 在更新时有一些价值吗?尝试调试。它是描述列的有效值吗?
  • 这是程序其他部分的一个错误,它已解决....抱歉耽误您的时间...谢谢您的帮助...
  • @nawfal: 好吧 - 严格来说,一个数据库表有 rows 和 columns,以及内存中的一个对象(例如您的 .NET 对象)是一个记录并且有字段。但是开发人员经常混淆这些术语 - 但我认为人们应该意识到这些差异,准确并在描述内容时使用正确的术语

标签: c# sql


【解决方案1】:

你应该试试 [Description]=@Description,因为 Description 词应该是 SQL 中的一种特殊关键字。

【讨论】:

    【解决方案2】:

    首先尝试检查您的代码并对其进行跟踪,然后查看 SQL Profiler 以获取从您的应用程序发送到 sql 的内容。 另请注意,Description 是 sql server 中的关键字。在 [ ] 之间使用它或在列名之前使用表名。 喜欢Factors.[Description] 整体更改您的查询如下:

    UPDATE Factors 
    SET    CodeFactor = @CodeFactor, [Date] = @Date, MobileNumber = @MobileNumber, 
           [Description]= @Description, TotalPrice = @TotalPrice, 
           ShouldPayPrice = @ShouldPayPrice 
           WHERE ID = @Original_ID; 
    SELECT   ID, CodeFactor, [Date], PersonName, MobileNumber, [Description], TotalPrice, 
             ShouldPayPrice, PaidPrice, Settlement, Kind 
    FROM     Factors 
    WHERE    ID = @Original_ID
    ORDER BY [Date] DESC;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-08
      • 2016-12-02
      • 1970-01-01
      • 2018-12-30
      • 1970-01-01
      • 2013-03-23
      相关资源
      最近更新 更多