更新查询适用于除一个之外的所有列

时间:2012-10-30 04:35:52

标签: c# sql

我的.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);

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

2 个答案:

答案 0 :(得分:0)

您应该尝试[描述] = @描述,因为描述字应该是SQL中的一种特殊关键字。

答案 1 :(得分:0)

首先尝试检查代码并对其进行跟踪,然后查看SQL事件探查器以获取从应用程序发送到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;