I want to update any columns of table TBL_Log if value entered from C# is not NULL. Here is my stored procedure:
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
I have tried to make this work but have not been successful.
code in class 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;
}
@Endvalue supplied in C# is notnullthen you want to update all rows where columnEndisNULLto@End, and similarly for all other parameters? The parameters are independent, i.e.@Startaffects only rows whereStartisNULLregardless of@EndorEnd?