如何从vb .net winform将空值传递给sql数据库 [英] How to pass a null value to sql database from vb .net winform

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

问题描述

我有一个表格列 workingfrom workingto 作为日期日期数据类型。

I am having a table column workedfrom and workedto as date date datatype.

如果我提供空值数据库应该接受我的空值。有一段时间我会停用此
" Workedfrom" 日期

If I supply null value database should accept my null value. Some time I will disable this "Workedfrom" date

如何编码。

kindly帮助我。

kindly help me.

cmd.Parameters.Add(" @workingfrom2",SqlDbType.DateTime).Value = Convert.ToDateTime(WrkdfrmDateTimeEditor2.Value)

cmd.Parameters.Add("@workedfrom2", SqlDbType.DateTime).Value = Convert.ToDateTime(WrkdfrmDateTimeEditor2.Value)

这是我的代码并显示将null转换为date数据类型的错误

this is my code and shows error in converting null to date datatype

推荐答案

我不知道你是如何使用的VB.Net中具有Null值的结构几乎是不可能的。 (只有你已经创建它并且从未使用它,它将有一个值。) 

I don't know how you are able to use a structure with a Null Value in VB.Net that is almost impossible. (Only if you have made it and never used it, it will have a value). 

但是,要将一个Nothing值从VB传递给SQL数据库,你可以使用DBNull .Value

However, to pass a Nothing value from VB to a SQL database, you can use DBNull.Value

但你似乎坚持使用.Net 1.0中过时的.Add而不是使用AddWithValue

But you seem to persist in using the obsolete .Add from .Net 1.0 use the AddWithValue instead

cmd.Parameters.AddWithValue(" @workingfrom2",CDate(WrkdfrmDateTimeEditor2.Value))

但是,你的WrkdfrmDateTimeEditor2.Value可能不是Nothing(C类程序语言中为Null),而是空(""")。 

However, probably is your WrkdfrmDateTimeEditor2.Value not Nothing (Null in C type program languages) but empty (""). 


这篇关于如何从vb .net winform将空值传递给sql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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