如何将vb.net中date的空值传递给sql存储过程? [英] How can I pass a null value for date in vb.net to sql stored procedure?

查看:188
本文介绍了如何将vb.net中date的空值传递给sql存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序是带有vb的asp.net.

My application is asp.net with vb.

在我的页面上,我有一个文本框用于输入日期.如果我没有输入日期,然后单击提交,则必须将空值传递给存储过程.

In my page I have a textbox for passing date. If I didn't enter date and on clicking submit, I have to pass null value to the stored procedure.

我尝试使用以下代码,例如DBNull.ValueDateTime.MinValue.在那种情况下,"#12:00:00#"代替了null.我必须通过Null.

I tried following codes such as DBNull.Value and DateTime.MinValue. In that case instead of null, "#12:00:00#" is passing. I have to pass Null.

推荐答案

只需为参数分配值DBNull.Value

Just assign the parameter the value DBNull.Value

如果您使用的是SqlParameter(感谢Jon),则可以在出现任何错误时像这样设置它

If you are using SqlParameter (thanks Jon) then you can set it like this if it gives any error

parameter.Value = DBNull.Value 

这篇关于如何将vb.net中date的空值传递给sql存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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