【发布时间】:2018-07-17 20:30:51
【问题描述】:
在 C# Windows 程序中,我想更新 SQL Server 表中的 Int 字段
int NewSeqno = MySeqno; // get current sequence number
NewSeqno++; // increment it
connection.Open();
// The following errors out saying that NewSeqno is not a column in the table.
// I want to update the field with the local variable NewSeqno.
command.CommandText = "UPDATE dbo.params SET NextSeqno = NewSeqno";
int recordsAffected = command.ExecuteNonQuery();
// The following statement, which writes a constant in the field, works fine.
command.CommandText = "UPDATE dbo.params SET NextSeqno = 123";
【问题讨论】:
-
You add a parameter to your
UPDATEstatement and then you bind your variable to that parameter. 到 MSDN 的链接有一条 UPDATE 语句,例如
标签: c# sql-server ado.net