如何将空变量从 C#.net 代码传递给 SQL 存储过程 [英] How to pass a null variable to a SQL Stored Procedure from C#.net code
本文介绍了如何将空变量从 C#.net 代码传递给 SQL 存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从一段 C#.net 代码中调用了一个 SQL 存储过程:
SqlHelper.ExecuteDataset(sqlConnection, CommandType.StoredProcedure, STORED_PROC_NAME, sqlParameters);
其中 sqlParameters
变量定义为:
SqlParameter[] sqlParameters = new SqlParameter[SQL_NUMBER_PARAMETERS];Log.Logger.Debug(string.Format("Running proc: {0} ", STORED_PROC_NAME));SqlParameters[0] = new SqlParameter("fieldID", SqlDbType.BigInt);SqlParameters[0].Value = fieldID;SqlParameters[0].Direction = ParameterDirection.Input;
我现在需要将另外两个参数传递给这个存储过程,(两者都是 SqlDateTime
类型),在这种情况下它们将 NULL.>
谢谢,
输入
解决方案
SqlParameters[1] = new SqlParameter("Date1", SqlDbType.SqlDateTime);SqlParameters[1].Value = DBNull.Value;SqlParameters[1].Direction = ParameterDirection.Input;
...然后复制第二个.
Im calling a SQL stored procedure from a piece of C#.net code:
SqlHelper.ExecuteDataset(sqlConnection, CommandType.StoredProcedure, STORED_PROC_NAME, sqlParameters);
where the sqlParameters
variable is defined as:
SqlParameter[] sqlParameters = new SqlParameter[SQL_NUMBER_PARAMETERS];
Log.Logger.Debug(string.Format("Running proc: {0} ", STORED_PROC_NAME));
SqlParameters[0] = new SqlParameter("fieldID", SqlDbType.BigInt );
SqlParameters[0].Value = fieldID;
SqlParameters[0].Direction = ParameterDirection.Input;
I need to now pass in another two parameters to this Stored Proc, (both are of type SqlDateTime
), which are going to NULL in this case.
Thanks,
IN
解决方案
SqlParameters[1] = new SqlParameter("Date1", SqlDbType.SqlDateTime);
SqlParameters[1].Value = DBNull.Value;
SqlParameters[1].Direction = ParameterDirection.Input;
...then copy for the second.
这篇关于如何将空变量从 C#.net 代码传递给 SQL 存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文