Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.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
Vb.net 第二排没有位置#_Vb.net - Fatal编程技术网

Vb.net 第二排没有位置#

Vb.net 第二排没有位置#,vb.net,Vb.net,我有一个包含重复项的.CSV。当我填写数据表时,我想过滤掉重复的数据并添加某些单元格 我的专栏: With table.Columns .Add(currentRow(0).ToString) '0 .Add(currentRow(3).ToString) '3 .Add(currentRow(5).ToString) '5 .Add(currentRow(6).ToString) '6

我有一个包含重复项的.CSV。当我填写数据表时,我想过滤掉重复的数据并添加某些单元格

我的专栏:

  With table.Columns
            .Add(currentRow(0).ToString) '0
            .Add(currentRow(3).ToString) '3
            .Add(currentRow(5).ToString) '5
            .Add(currentRow(6).ToString) '6
            .Add(currentRow(8).ToString) '8
        End With
我的标题:

table.Rows.Add(table.Columns(0).ToString,table.Columns(1).ToString,table.Columns(2).ToString,table.Columns(3).ToString,table.Columns(4).ToString)

当我继续检查currentRows到我的表中已经存在的内容时,我得到一个错误:“位置#没有行。”

只有当我有这段代码定义了我的头,但格式不正确时,它才会起作用

 With table.Rows
                .Add(currentRow(0).ToString) '0
                .Add(currentRow(3).ToString) '3
                .Add(currentRow(5).ToString) '5
                .Add(currentRow(6).ToString) '6
                .Add(currentRow(8).ToString) '8
            End With
这是我的If语句,我将currentRow的元素与第一列和第一行进行比较

 If currentRow(0).ToString Is table.Rows(someVal).Item(0) Then

在测试中,我可以看到格式正确的头,但我的If语句无法识别它

Is关键字确定两个对象引用是否引用同一个对象,但不比较对象的值。改用
=

If currentRow(0).ToString = table.Rows(someVal).Item(0) Then 

DataTable是筛选重复项的正确对象吗?考虑创建一个以适当的方式表示数据的类。如果在类中重写
Equals
方法,那么使用LINQ就可以轻松地获取不同的对象

Dim list = New List(Of MyClass)

' Add objects
list.Add(New MyClass(...))
list.Add(New MyClass(...))
...

'Get unique objects
Dim unique = list.Distinct()
For Each obj As MyClass In unique
    ' process obj
Next

更改if语句没有帮助。我只是使用一个数据表作为中间人,从一个文件中整理我正在读取的内容。每一个输入都会与之前的输入(如果有的话)进行检查。然后将找到的任何重复项合并。似乎每当我尝试从datatable访问一行时,我都会被告知该行不存在,但当我将datatable写入文件时,我可以很容易地看到输出。为什么要在第一个代码段中添加行作为列?是否混淆了行和列?currentRow()是从textFieldParser获取的字符串数组。我只是从currentRow中选取元素来创建列(我的表格宽度),我不知道发生了什么。使用调试器分析代码。在失败的行上设置断点。在执行该行之前,执行将停止。您可以查看每个变量和参数的值,检查行数和列数等。