Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 当新值是局部变量时,SQL更新的语法是什么_C#_Sql Server_Ado.net - Fatal编程技术网

C# 当新值是局部变量时,SQL更新的语法是什么

C# 当新值是局部变量时,SQL更新的语法是什么,c#,sql-server,ado.net,C#,Sql Server,Ado.net,在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 t

在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";

必须将参数传递给SQL查询

更新命令文本,如下所示-

command.CommandText = "UPDATE dbo.params SET NextSeqno = @NewSeqno";
将此行添加到pass参数

command.Parameters.Add("@NewSeqno", SqlDbType.Int).Value = NewSeqno;

你应该学会如何去做和做。例如,指向MSDN的链接有一个更新声明。同意,更新了我的答案。