ASP.NET 2.0和ObjectDataBinding [英] ASP.NET 2.0 and ObjectDataBinding

查看:67
本文介绍了ASP.NET 2.0和ObjectDataBinding的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个ASP.NET 2.0项目,我有一个BAL和DAL层。我是
将数据集从DAL传递给BAL。 BAL正在将泛型传回

到演示文稿中。一切正常,但是,我注意到我的

代码在BAL中做了类似的问题:

List< JobSummary> jobSummary = new List< JobSummary>();


foreach(ds.Tables [0] .Rows中的DataRow行)

{

jobSummary.Add(new JobSummaryClass((Int32)row [" JobNum"],

(DateTime)row [" StartDate"],(DateTime)row [" EndDate"] ));

}


返回jobSummary

我在上面的jobSummary.Add()上收到了一个INvalidCastException。我注意到在某些行上,我的EndTime为空。我暂时修复了这个

,将代码包含在try / catch中,而不是重新抛出异常。但是

然后跳过这条记录。


如何解决这个问题有什么选择?

解决方案

你可以使用

if(row [" StartDate"]!= DBNull.Value)

{

//

}




if(!row.IsNull(" StartDate"))

{

//

}

HTH


埃尔顿王


" dm1608"写道:

我正在做一个ASP.NET 2.0项目,我有一个BAL和DAL层。我将DataSet从DAL传递给BAL。 BAL正在将泛型传递回演示文稿。一切正常,但是,我注意到我的
代码在BAL中做了类似的问题:

List< JobSummary> jobSummary = new List< JobSummary>();

foreach(ds.Tables [0] .Rows中的DataRow行)
{jobSummary.Add(new JobSummaryClass((Int32) )row [" JobNum"],
(DateTime)row [" StartDate"],(DateTime)row [" EndDate"]));
}

return jobSummary

我在上面的jobSummary.Add()上收到了一个INvalidCastException。我注意到在某些行上,我的EndTime为空。我暂时修复了这个
,将代码放在try / catch中,而不是重新抛出异常。但是
然后跳过这条记录。

如何解决这个问题有什么选择?



< blockquote>但我需要为EndTime DateTime变量赋值NULL,以便

填充我的集合以供显示。我如何解决这个问题?


" Elton W" <埃尔**** @ discussions.microsoft.com>在消息中写道

新闻:EA ********************************** @ microsof t.com ...

你可以使用

if(row [" StartDate"]!= DBNull.Value)
{
/ /


if(!row.IsNull(" StartDate"))
{
//
}

HTH

Elton Wang

" dm1608"写道:

我正在做一个ASP.NET 2.0项目,我有一个BAL和DAL层。我将DataSet从DAL传递给BAL。 BAL正在将仿制品传回给演示文稿。一切正常,但是,我注意到我的
代码在BAL中做了类似的问题:

List< JobSummary> jobSummary = new List< JobSummary>();

foreach(ds.Tables [0] .Rows中的DataRow行)
{jobSummary.Add(new JobSummaryClass((Int32) )row [" JobNum"],
(DateTime)row [" StartDate"],(DateTime)row [" EndDate"]));
}

return jobSummary

我在上面的jobSummary.Add()上收到了一个INvalidCastException。我注意到在某些行上,我的EndTime为空。我暂时修复了
这个
把代码放在try / catch中,而不是重新抛出异常。
但是
然后就会跳过这条记录。
<如何解决这个问题我有哪些选择?



>但是我需要为EndTime DateTime变量赋值NULL,以便

填充我的集合以供显示。我如何解决这个问题?




如何使用Nullable DateTime? - 如果

值为DBNull,则不要指定任何内容。


class JobSummaryItem

{

// ...


公共日期时间?结束时间

{

得到{...}

}

}


I''m doing an ASP.NET 2.0 project where I have a BAL and DAL layer. I''m
passing a DataSet from the DAL to the BAL. The BAL is passing generics back
to the presentation. All works fine, however, I noticed a problem with my
code that does something like this in the BAL:
List<JobSummary> jobSummary = new List<JobSummary>();

foreach (DataRow row in ds.Tables[0].Rows)
{
jobSummary.Add(new JobSummaryClass((Int32)row["JobNum"],
(DateTime)row["StartDate"],(DateTime)row["EndDate"]));
}

return jobSummary
I''m receiving an INvalidCastException on my jobSummary.Add() above. I
noticed that on some rows, my EndTime is null. I''m temporarily fixed this
by enclosing the code in a try/catch and not rethrowing the exception. But
then this record is skipped.

What are my options with how to fix this?

解决方案

You can use
if (row["StartDate"] != DBNull.Value)
{
//
}

or
if (!row.IsNull("StartDate"))
{
//
}
HTH

Elton Wang

"dm1608" wrote:

I''m doing an ASP.NET 2.0 project where I have a BAL and DAL layer. I''m
passing a DataSet from the DAL to the BAL. The BAL is passing generics back
to the presentation. All works fine, however, I noticed a problem with my
code that does something like this in the BAL:
List<JobSummary> jobSummary = new List<JobSummary>();

foreach (DataRow row in ds.Tables[0].Rows)
{
jobSummary.Add(new JobSummaryClass((Int32)row["JobNum"],
(DateTime)row["StartDate"],(DateTime)row["EndDate"]));
}

return jobSummary
I''m receiving an INvalidCastException on my jobSummary.Add() above. I
noticed that on some rows, my EndTime is null. I''m temporarily fixed this
by enclosing the code in a try/catch and not rethrowing the exception. But
then this record is skipped.

What are my options with how to fix this?



But I need to assign NULL to the EndTime DateTime variable in order to
populate my collection for display. How do I get around this?


"Elton W" <El****@discussions.microsoft.com> wrote in message
news:EA**********************************@microsof t.com...

You can use
if (row["StartDate"] != DBNull.Value)
{
//
}

or
if (!row.IsNull("StartDate"))
{
//
}
HTH

Elton Wang

"dm1608" wrote:

I''m doing an ASP.NET 2.0 project where I have a BAL and DAL layer. I''m
passing a DataSet from the DAL to the BAL. The BAL is passing generics
back
to the presentation. All works fine, however, I noticed a problem with
my
code that does something like this in the BAL:
List<JobSummary> jobSummary = new List<JobSummary>();

foreach (DataRow row in ds.Tables[0].Rows)
{
jobSummary.Add(new JobSummaryClass((Int32)row["JobNum"],
(DateTime)row["StartDate"],(DateTime)row["EndDate"]));
}

return jobSummary
I''m receiving an INvalidCastException on my jobSummary.Add() above. I
noticed that on some rows, my EndTime is null. I''m temporarily fixed
this
by enclosing the code in a try/catch and not rethrowing the exception.
But
then this record is skipped.

What are my options with how to fix this?



> But I need to assign NULL to the EndTime DateTime variable in order to

populate my collection for display. How do I get around this?



How about using a Nullable DateTime? - and then don''t assign anything if the
value is DBNull.

class JobSummaryItem
{
// ...

public DateTime? EndTime
{
get { ... }
}
}


这篇关于ASP.NET 2.0和ObjectDataBinding的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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