由于某些原因,在我的每个语句的以下段中,它声明csv数据不能为null,即使你看到它们创建csvData对象时它在循环中创建的是正确的位置。 / p>
For Each thisDocument As String In documentList
filename = Path.GetFileName(thisDocument)
SiteId = filename.Substring(0, filename.IndexOf("_"))
Dim orderNumbers As String()
Dim csvData As New DataTable
Dim importUtils As New ImportController
filename = Path.GetFileName(thisDocument)
orderNumbers = filename.Split("_")
location = filename.Substring(0, 3)
importUtils = New ImportController(cfb.TargetFolder & filename)
csvData = importUtils.ConvertCsvToDatatable(True)
ImportDataTableToSql(cfb.TargetFolder & filename, csvData, cfb.StoreCompany)
Next
编辑以显示convertcsvtodatatable()
Public Function ConvertCsvToDatatable(ByVal ColumnNames As Boolean) As DataTable
Try
Dim dt As New DataTable
For Each columnName In GetColumnsfromCsv(ColumnNames, ",")
dt.Columns.Add(columnName)
Next
Dim fileReader As New StreamReader(FileName)
If ColumnNames Then
fileReader.ReadLine()
End If
Dim line As String = fileReader.ReadLine
While Not IsNothing(line)
line = line.Replace(Chr(34), "")
dt.Rows.Add(line.Split(","))
line = fileReader.ReadLine
End While
fileReader.Close()
Return dt
Catch ex As Exception
'log to file
End Try
Return Nothing
End Function