可以为空的对象必须具有值。 [英] Nullable object must have a value.

查看:63
本文介绍了可以为空的对象必须具有值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还没有找到一个满意的解决方案来解决这个问题。它涉及

VB.NET 2.0和日期时间问题。


我有一个表格要求以dd / mm / yyyy提交日期

格式。如果提交,则按如下方式处理:


------------------------- -----------

公共子更新(ByVal sender As Object,ByVal e As System.EventArgs)

处理ConfirmEdit。点击


''***声明

Dim RequestedDate为Nullable(日期)


''* **填充

RequestedDate = ERequestedDate.Text


Result1 = DataTable.Update(Id,RequestedDate,ConfirmedDate)


结束子


---------------------------------- ----

DataTable.Update表示使用的数据表,方法是调用基于 />
id赋予它。


现在,上面的代码是一个简化 - 但原则是

相同。 ConfirmedDate可能没有任何内容 - 并导致

Nullable对象必须具有值。 "错误。


DataTable允许DBNull。

---------------------- -----------------------

DataType = System.DateTime

AllowDBNull = True

DefaultValue =< DBNull>

------------------------------- --------------


存储过程允许空值:

--------- ------------------------------------

CREATE PROCEDURE [dbo]。 [更新]

(@Id int,

@RequestedDate datetime = null,

@ConfirmedDate datetime = null)

AS

BEGIN

~~~~~~~

END

GO

---------------------------------------------


数据库允许Nulls:

-------------------------- -------------------

DataType = datetime(8)

Null = True

DefaultValue = Null

------------------------------------- --------

但是当ConfirmedDate值为
没有任何内容。有没有人有任何想法如何解决这个问题?

I have yet to find a satisfactory solution to this problem. It involves
VB.NET 2.0 and datetime issues.

I have a form that asks for a Date to be submitted in dd/mm/yyyy
format. When this is submitted it then is then dealt with as follows:

------------------------------------

Public Sub Update(ByVal sender As Object, ByVal e As System.EventArgs)
Handles ConfirmEdit.Click

''*** Declare
Dim RequestedDate As Nullable(Of Date)

''*** Populate
RequestedDate=ERequestedDate.Text

Result1 = DataTable.Update(Id, RequestedDate, ConfirmedDate)

End Sub

--------------------------------------

The DataTable.Update represents the datatable used and the method is
calling a stored procedure that updates a particular record based on an
id given to it.

Now, the above code is a simplification - but the principle si the
same. The ConfirmedDate may have nothing in it - and causes the
"Nullable object must have a value. " error.

The DataTable allows for DBNull.
---------------------------------------------
DataType=System.DateTime
AllowDBNull=True
DefaultValue=<DBNull>
---------------------------------------------

The Stored Procedure allows for Nulls:
---------------------------------------------
CREATE PROCEDURE [dbo].[Update]
(@Id int,
@RequestedDate datetime = null,
@ConfirmedDate datetime = null)
AS
BEGIN
~~~~~~~
END
GO
---------------------------------------------

The Database allows For Nulls:
---------------------------------------------
DataType=datetime (8)
Null=True
DefaultValue=Null
---------------------------------------------
But yet the update will not work when the ConfirmedDate value has
nothing in it. Does anybody have any ideas how to get round this?

推荐答案

当你有一个空的日期时,你试图传递DBNull.Value到

存储的Procededure而不是null日期?


问候,

Brian K. Williams

" scparker" < st ******* @ hotmail.comwrote in message

news:11 ********************** @ q2g2000cwa.googlegro ups.com ...
When you have an empty date have you tried to pass DBNull.Value to the
Stored Procededure instead of a null date?

Regards,
Brian K. Williams
"scparker" <st*******@hotmail.comwrote in message
news:11**********************@q2g2000cwa.googlegro ups.com...

>我还没有找到一个满意的解决方案来解决这个问题。它涉及

VB.NET 2.0和日期时间问题。


我有一个表格要求以dd / mm / yyyy提交日期

格式。如果提交,则按如下方式处理:


------------------------- -----------

公共子更新(ByVal sender As Object,ByVal e As System.EventArgs)

处理ConfirmEdit。点击


''***声明

Dim RequestedDate为Nullable(日期)


''* **填充

RequestedDate = ERequestedDate.Text


Result1 = DataTable.Update(Id,RequestedDate,ConfirmedDate)


结束子


---------------------------------- ----

DataTable.Update表示使用的数据表,方法是调用基于 />
id赋予它。


现在,上面的代码是一个简化 - 但原则是

相同。 ConfirmedDate可能没有任何内容 - 并导致

Nullable对象必须具有值。 "错误。


DataTable允许DBNull。

---------------------- -----------------------

DataType = System.DateTime

AllowDBNull = True

DefaultValue =< DBNull>

------------------------------- --------------


存储过程允许空值:

--------- ------------------------------------

CREATE PROCEDURE [dbo]。 [更新]

(@Id int,

@RequestedDate datetime = null,

@ConfirmedDate datetime = null)

AS

BEGIN

~~~~~~~

END

GO

---------------------------------------------


数据库允许Nulls:

-------------------------- -------------------

DataType = datetime(8)

Null = True

DefaultValue = Null

------------------------------------- --------


但是当ConfirmedDate值有时,更新将不起作用

没什么。有没有人有任何想法如何绕过这个?
>I have yet to find a satisfactory solution to this problem. It involves
VB.NET 2.0 and datetime issues.

I have a form that asks for a Date to be submitted in dd/mm/yyyy
format. When this is submitted it then is then dealt with as follows:

------------------------------------

Public Sub Update(ByVal sender As Object, ByVal e As System.EventArgs)
Handles ConfirmEdit.Click

''*** Declare
Dim RequestedDate As Nullable(Of Date)

''*** Populate
RequestedDate=ERequestedDate.Text

Result1 = DataTable.Update(Id, RequestedDate, ConfirmedDate)

End Sub

--------------------------------------

The DataTable.Update represents the datatable used and the method is
calling a stored procedure that updates a particular record based on an
id given to it.

Now, the above code is a simplification - but the principle si the
same. The ConfirmedDate may have nothing in it - and causes the
"Nullable object must have a value. " error.

The DataTable allows for DBNull.
---------------------------------------------
DataType=System.DateTime
AllowDBNull=True
DefaultValue=<DBNull>
---------------------------------------------

The Stored Procedure allows for Nulls:
---------------------------------------------
CREATE PROCEDURE [dbo].[Update]
(@Id int,
@RequestedDate datetime = null,
@ConfirmedDate datetime = null)
AS
BEGIN
~~~~~~~
END
GO
---------------------------------------------

The Database allows For Nulls:
---------------------------------------------
DataType=datetime (8)
Null=True
DefaultValue=Null
---------------------------------------------
But yet the update will not work when the ConfirmedDate value has
nothing in it. Does anybody have any ideas how to get round this?





Brian Williams写道:

Brian Williams wrote:

当你有一个空的日期时,你试图将DBNull.Value传递给

存储的Procededure而不是null日期?


问候,

Brian K. Williams

When you have an empty date have you tried to pass DBNull.Value to the
Stored Procededure instead of a null date?

Regards,
Brian K. Williams



我试过看我怎么能够在我的代码中使用
来指定DBNull.Value但是到目前为止每次尝试都失败了。鉴于我使用的是一个

存储过程,我如何能够将ConfirmedDate

值指定为DBNull.Value?


此致,

Stephen

I have tried to see how I would be able to dictate the DBNull.Value in
my code but every attempt has failed so far. Given that I am using a
stored procedure, how would I be able to dictate the ConfirmedDate
value to be of DBNull.Value?

Sincerely,
Stephen


" scparker" < st ******* @ hotmail.comwrote in message

news:11 ********************** @ a75g2000cwd.googlegr oups.com ...
"scparker" <st*******@hotmail.comwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...

Brian Williams写道:
Brian Williams wrote:

>当你有您是否尝试将DBNull.Value传递给
存储的Proceded而不是空日期?

问候,
Brian K. Williams



我试图看看如何在我的代码中指示DBNull.Value

但是到目前为止每次尝试都失败了。鉴于我正在使用

存储过程,我如何能够将ConfirmedDate

值指定为DBNull.Value?


I have tried to see how I would be able to dictate the DBNull.Value in
my code but every attempt has failed so far. Given that I am using a
stored procedure, how would I be able to dictate the ConfirmedDate
value to be of DBNull.Value?



DateTime? dtmDate;

SqlParameter objSqlParameter;


objSqlParameter = new SqlParameter(" @ pdtmDate",SqlDbType.DateTime);

objSqlParameter .IsNullable = true;

objSqlParameter.Value = dtmDate ?? (对象)DBNull.Value;

DateTime? dtmDate;
SqlParameter objSqlParameter;

objSqlParameter = new SqlParameter("@pdtmDate", SqlDbType.DateTime);
objSqlParameter.IsNullable = true;
objSqlParameter.Value = dtmDate ?? (object)DBNull.Value;


这篇关于可以为空的对象必须具有值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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