【发布时间】:2017-01-09 12:25:23
【问题描述】:
如果从 C# 输入的值不是 NULL,我想更新表 TBL_Log 的任何列。这是我的存储过程:
Alter PROCEDURE [dbo].[SP_Update_User]
(@User_id as int,@User_Names as nvarchar(max),@End as char(8),@Start as nvarchar(max) ,@Count as int)
AS
BEGIN
UPDATE [dbo].[TBL_Log]
SET User_Names = @User_Names
,[Start] = @start
,[End] = @End
,[Count] = @Count
where User_id = @User_id
END
我尝试过完成这项工作,但没有成功。
D1 类代码:
public static DataSet Update_User(int @User_id, string @User_Names, string @End, string @Start, int @Count)
{
SqlConnection myConnection = new SqlConnection(strConecctionString);
SqlDataAdapter sqlcmd = new SqlDataAdapter("SP_Update_UserData_Bot", myConnection);
sqlcmd.SelectCommand.CommandType = CommandType.StoredProcedure;
SqlParameter parameterID_category_ID = new SqlParameter("@User_id", SqlDbType.Int);
parameterID_category_ID.Value = User_id;
sqlcmd.SelectCommand.Parameters.Add(parameterID_category_ID);
SqlParameter parameterID_Part_ID = new SqlParameter("@User_Names", SqlDbType.Int);
parameterID_Part_ID.Value = User_Names;
sqlcmd.SelectCommand.Parameters.Add(parameterID_Part_ID);
SqlParameter parameterID_Series_ID = new SqlParameter("@End", SqlDbType.Char);
parameterID_Series_ID.Value = End;
sqlcmd.SelectCommand.Parameters.Add(parameterID_Series_ID);
SqlParameter parameterID_Model_ID = new SqlParameter("@start", SqlDbType.NVarChar);
parameterID_Model_ID.Value = start;
sqlcmd.SelectCommand.Parameters.Add(parameterID_Model_ID);
SqlParameter parameterID_Count = new SqlParameter("@Count", SqlDbType.Int);
parameterID_Count.Value = Count;
sqlcmd.SelectCommand.Parameters.Add(parameterID_Count);
sqlcmd.SelectCommand.CommandTimeout = int.MaxValue;
DataSet DS = new DataSet();
sqlcmd.Fill(DS);
return DS;
}
【问题讨论】:
-
您的问题不清楚。您是说如果 C# 中提供的
@End值不是null,那么您想要将列End为NULL的所有行更新为@End,并且对于所有其他参数也是如此?参数是独立的,即@Start只影响Start为NULL的行,而不管@End或End? -
不是您问题的答案,而是您应该阅读的文章。 sqlperformance.com/2012/10/t-sql-queries/sp_prefix
标签: sql sql-server tsql null sql-update