简单的问题是,如何将 MS Query 中的字段值加 1?我正在尝试将 1 (+1) 添加到int
使用参数化方法在我的 SQL Server 数据库中创建列。类似于变量上的 i++ 操作。我正在使用以下方法:
public static int UpdateFieldCount(int parameterId)
{
// variable to hold the number of rows updated or the success of the query
int updatesuccess = 0;
// build your connection string
string connectionstring = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(connectionstring);
// build your SQL Query statement
string SQLString = "UPDATE TableName SET TableField + 1 WHERE SomeFilterField = @ParameterID";
SqlCommand sqlcmd = new SqlCommand(SQLString, conn);
sqlcmd.Parameters.AddWithValue("@ParameterID", parameterID);
conn.Open();
updatesuccess = sqlcmd.ExecuteNonQuery();
conn.Close();
return updatesuccess;
}
此方法引发以下与我的 sql 查询中的加号 (+) 相关的错误:
“+”附近的语法不正确。
描述:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。
异常详细信息:System.Data.SqlClient.SqlException:“+”附近的语法不正确。
来源错误:
315行:
第 316 行:conn.Open();
第 317 行:updatesuccess = sqlcmd.ExecuteNonQuery();
第 318 行:conn.Close();
319行:
源文件:c:\testdevlocation\appname\App_Code\ClassFileName.cs 行:317
对此有什么建议吗?
您需要一个值和一个字段来分配它。其值为TableField + 1
,所以任务是:
SET TableField = TableField + 1
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)