如何将空变量传递给从C#.NET code存储过程的SQL [英] How to pass a null variable to a SQL Stored Procedure from C#.net code

查看:124
本文介绍了如何将空变量传递给从C#.NET code存储过程的SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可是从一块C#.NET code的调用SQL存储过程:

  SqlHelper.ExecuteDataset(SqlConnection的,CommandType.StoredProcedure,STORED_PROC_NAME,sqlParameters);

其中 sqlParameters 变量定义为:

 的SqlParameter [] = sqlParameters新的SqlParameter [SQL_NUMBER_PARAMETERS]        Log.Logger.Debug(的String.Format(运行PROC:{0},STORED_PROC_NAME));        SqlParameters [0] =新的SqlParameter(fieldID,SqlDbType.BigInt);
        SqlParameters [0] .value的= fieldID;
        SqlParameters [0] .Direction = ParameterDirection.Input;

我现在需要通过另外两个参数,这个存储过程,(都是类型的 SQLDATETIME ),这两个项目的 NULL 的在这种情况下

谢谢,


解决方案

  SqlParameters [1] =新的SqlParameter(日期1,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 code存储过程的SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆