首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DataView.Count()返回多个值

问DataView.Count()返回多个值
EN

Stack Overflow用户
提问于 2015-06-05 01:47:58
回答 1查看 150关注 0票数 2

我对这一切都有点陌生,所以我会尽量具体一点..我正在尝试创建一个在另一个表单中显示两个日期的按钮。因此,我写了以下内容:

代码语言:javascript
复制
DataView dv = new DataView(dataComercioDataSet.Comex);
dv.Sort = "Id";
int ixe = dv.Find(idTextBox.Text);
DateTime embarque = Convert.ToDateTime(dv[ixe]["FechaEmbarque"]);
otherForm.fechaEmbarqueDateTimePicker.Value = embarque;
DateTime vencimiento = Convert.ToDateTime(dv[ixe]["FechaVencimiento"]);
otherForm.fechaVencimientoDateTimePicker.Value = vencimiento;
otherForm.idBox1.Text = dv[ixe]["Id"].ToString();
this.comexTableAdapter.FillBy3(this.dataComercioDataSet.Comex, c41TextBox.Text);

现在,当我单击按钮时,它捕捉到一个异常,表明它是一个DBNull对象。因此,我决定通过添加以下内容来测试它:

代码语言:javascript
复制
if (dv.Count == 1)
{
    MessageBox.Show("1");
}
if (dv.Count == 0) ;
{
    MessageBox.Show("0");
}

它同时显示了这两种情况!因为异常声明它是DBNull,所以我认为dv.find必须返回0,所以我计算如下:

代码语言:javascript
复制
if (ixe == 0)
{
    ixe = 1;
    DateTime embarque = Convert.ToDateTime(dv[ixe]["FechaEmbarque"]);
    otherForm.fechaEmbarqueDateTimePicker.Value = embarque;
    DateTime vencimiento = Convert.ToDateTime(dv[ixe]["FechaVencimiento"]);
    otherForm.fechaVencimientoDateTimePicker.Value = vencimiento;
    otherForm.idBox1.Text = dv[ixe]["Id"].ToString();

    this.comexTableAdapter.FillBy3(this.dataComercioDataSet.Comex, c41TextBox.Text);
}

但是当我这样做的时候,例外的是索引1要么是负的,要么比行数高(它是西班牙语的,我不知道这是不是实际的翻译),我想我不太明白DataView.Find()实际上是如何索引结果的,我的意思是,行1=1还是0?

提前感谢!

EN

回答 1

Stack Overflow用户

发布于 2015-06-05 20:47:05

设法解决了这个问题,不知何故改变了

代码语言:javascript
复制
DataView dv = new DataView(dataComercioDataSet.Comex);

至

代码语言:javascript
复制
 DataView dv = new DataView();
          dv = dataComercioDataSet.Comex.AsDataView();

解决了这个问题,虽然不确定为什么.

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30650719

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档