I am parsing through each line of a fixed length text file. I am retrieving 13 values from this text file and inserting them into variables of multiple datatypes. Eventually I will need to add these values to a row in a datatable, but the problem is I don't know how to do this. I tried looping through the columns and tried inserting the right variable in the right column. How do I add each of the variables below to the corresponding column in a datatable all in the same row?
Here are my variables:
Dim vendorName As String 'a
Dim vendorNum As Integer 'b
Dim CheckNum As String 'c - with checkNum and batch no combined
Dim depositDate As String 'd
Const crAccount As Integer = 102006 'e
Dim totCount As Integer ' f
Const blank As String = "" 'g
Const num As Integer = 1 'h
Dim qtr As Integer 'i
Dim custName As String 'j
Dim acctNum As Integer 'k
Dim headerAmount(headerCounter) As Double ' '// Not in the list
Dim detailAmount As Double 'l
Dim state As String 'm
Dim batchNo As String 'n -set this to string to retrieve the 00 or 01 or however many batches there is.
Dim checkNo As String 'o
Here are my columns:
dt.Columns.Add("Vendor #")
dt.Columns.Add("Vendor Name")
dt.Columns.Add("Check #")
dt.Columns.Add("Date")
dt.Columns.Add("102006")
dt.Columns.Add("#")
dt.Columns.Add("Blank")
dt.Columns.Add("1")
dt.Columns.Add("12QTR")
dt.Columns.Add("Client Name")
dt.Columns.Add("Acct No")
dt.Columns.Add("Amt")
dt.Columns.Add("State")
dt.Columns.Add("Batch No")
dt.Columns.Add("Check Number")
Here is the loop I tried, but it is adding each variable to it's own row:
For Each col As DataColumn In dt.Columns
If col.ColumnName = "Vendor #" Then
dt.Rows.Add(vendorNum)
ElseIf col.ColumnName = "Vendor Name" Then
dt.Rows.Add(vendorName)
ElseIf col.ColumnName = "Check #" Then
dt.Rows.Add(checkNo)
ElseIf col.ColumnName = "Date" Then
dt.Rows.Add(depositDate)
ElseIf col.ColumnName = "102006" Then
dt.Rows.Add(crAccount)
ElseIf col.ColumnName = "#" Then
dt.Rows.Add(totCount)
ElseIf col.ColumnName = "Blank" Then
dt.Rows.Add(blank)
ElseIf col.ColumnName = "1" Then
dt.Rows.Add(num)
ElseIf col.ColumnName = "12QTR" Then
dt.Rows.Add(qtr)
ElseIf col.ColumnName = "Client Name" Then
dt.Rows.Add(custName)
ElseIf col.ColumnName = "Acct No" Then
dt.Rows.Add(acctNum)
ElseIf col.ColumnName = "Amt" Then
dt.Rows.Add(detailAmount)
ElseIf col.ColumnName = "State" Then
dt.Rows.Add(state)
ElseIf col.ColumnName = "Batch No" Then
dt.Rows.Add(batchNo)
ElseIf col.ColumnName = "Check Number" Then
dt.Rows.Add(CheckNum)
End If
'dt.Rows.Add(vendorNum & vendorName & checkNo & depositDate &
'crAccount & totCount & blank & num & qtr & custName & acctNum
'& detailAmount & state & batchNo & CheckNum)
'// I also tried concatenating each of the parameters together
' and when I do this it is only trying to insert in the Vendor # column.
Next
This doesn't seem like it would be too difficult, but I can't find any examples of this. Any help would be appreciated. Thanks