count()返回多个值

本文关键字:返回 count | 更新日期: 2023-09-27 17:53:17

我对这一切都有点陌生,所以我会尽量具体。我试图创建一个按钮,将在另一种形式显示两个日期。所以我写了这个:

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对象。所以我决定通过添加以下内容来测试它:

if (dv.Count == 1)
{
    MessageBox.Show("1");
}
if (dv.Count == 0) ;
{
    MessageBox.Show("0");
}

两者都显示了!由于异常声明它是DBNull,我估计dv。find必须返回0,所以我认为:

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 ?

提前感谢!

count()返回多个值

设法解决这个问题,以某种方式更改

DataView dv = new DataView(dataComercioDataSet.Comex);

 DataView dv = new DataView();
          dv = dataComercioDataSet.Comex.AsDataView();

解决了问题,但不确定为什么…