Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Count()返回多个值_C#_Database_Winforms_Visual Studio 2013_Dataview - Fatal编程技术网

C# Count()返回多个值

C# Count()返回多个值,c#,database,winforms,visual-studio-2013,dataview,C#,Database,Winforms,Visual Studio 2013,Dataview,我对这一切都不太熟悉,所以我会尽量说得具体一点。。 我正在尝试创建一个按钮,它将以另一种形式显示两个日期。所以我写了这个: DataView dv = new DataView(dataComercioDataSet.Comex); dv.Sort = "Id"; int ixe = dv.Find(idTextBox.Text); DateTime embarque = Convert.ToDateTime(dv[ixe]["FechaEmbarque"]); otherForm.fechaE

我对这一切都不太熟悉,所以我会尽量说得具体一点。。 我正在尝试创建一个按钮,它将以另一种形式显示两个日期。所以我写了这个:

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


提前谢谢

设法解决了这个问题,但在某种程度上有所改变

DataView dv = new DataView(dataComercioDataSet.Comex);

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

您会发现在C#中,集合是0索引的,这意味着第一项是索引0。
 DataView dv = new DataView();
          dv = dataComercioDataSet.Comex.AsDataView();