Hello--
I'm stuck! I'm trying to parse a text file into an array and then insert it into a SQL table- now It looks like it's inserting only one field into the DB and doesn't do anything else-- something is wrong!!! Not that great with arrays so here is what I tried to use:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'File to string vars
Dim objSRFile As StreamReader
Dim strInput, arrStrInput() As String
Dim intCurrPos As Integer
Dim DocumentDate As String
Dim ISAID As String
Dim SetID As String
Dim ControlNumber As String
Dim GroupControlNumber As String
Dim GroupType As String
Dim InvoiceNbr As String
Dim Comments As String
Dim RecFlag As String
Dim TranslationStatus As Char
'DB vars
Dim strSQL As String
Dim conn As New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
Dim objCmd As SqlCommand
objSRFile = File.OpenText("C:\sundaytest.txt")
While objSRFile.Peek <> -1
strInput = objSRFile.ReadLine
Dim textdelimiter As String
textdelimiter = " "
arrStrInput = Split(strInput, textdelimiter)
For intCurrPos = 0 To arrStrInput.Length - 1
Select Case intCurrPos
Case 0
ISAID = arrStrInput(intCurrPos)
Case 1
InvoiceNbr = arrStrInput(intCurrPos)
Case 2
TranslationStatus = arrStrInput(intCurrPos)
Case 3
GroupControlNumber = arrStrInput(intCurrPos)
Case 4
DocumentDate = arrStrInput(intCurrPos)
Case 5
ControlNumber = arrStrInput(intCurrPos)
End Select
Next
strSQL = "insert into InovisInt_Lisa (ISAID, InvoiceNbr, TranslationStatus, GroupControlNumber, DocumentDate, ControlNumber, Comments, RecFlag) values ('" & ISAID & "', '" & InvoiceNbr & "','" & TranslationStatus & "','" & GroupControlNumber & "','" & DocumentDate & "','" & ControlNumber & "','No Comments','N')"
objCmd = New SqlCommand(strSQL, conn)
conn.Open()
objCmd.ExecuteNonQuery()
conn.Close()
End While
objSRFile.Close()
Any advice appreciated...
Thanks,
Lisa
I'm stuck! I'm trying to parse a text file into an array and then insert it into a SQL table- now It looks like it's inserting only one field into the DB and doesn't do anything else-- something is wrong!!! Not that great with arrays so here is what I tried to use:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'File to string vars
Dim objSRFile As StreamReader
Dim strInput, arrStrInput() As String
Dim intCurrPos As Integer
Dim DocumentDate As String
Dim ISAID As String
Dim SetID As String
Dim ControlNumber As String
Dim GroupControlNumber As String
Dim GroupType As String
Dim InvoiceNbr As String
Dim Comments As String
Dim RecFlag As String
Dim TranslationStatus As Char
'DB vars
Dim strSQL As String
Dim conn As New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
Dim objCmd As SqlCommand
objSRFile = File.OpenText("C:\sundaytest.txt")
While objSRFile.Peek <> -1
strInput = objSRFile.ReadLine
Dim textdelimiter As String
textdelimiter = " "
arrStrInput = Split(strInput, textdelimiter)
For intCurrPos = 0 To arrStrInput.Length - 1
Select Case intCurrPos
Case 0
ISAID = arrStrInput(intCurrPos)
Case 1
InvoiceNbr = arrStrInput(intCurrPos)
Case 2
TranslationStatus = arrStrInput(intCurrPos)
Case 3
GroupControlNumber = arrStrInput(intCurrPos)
Case 4
DocumentDate = arrStrInput(intCurrPos)
Case 5
ControlNumber = arrStrInput(intCurrPos)
End Select
Next
strSQL = "insert into InovisInt_Lisa (ISAID, InvoiceNbr, TranslationStatus, GroupControlNumber, DocumentDate, ControlNumber, Comments, RecFlag) values ('" & ISAID & "', '" & InvoiceNbr & "','" & TranslationStatus & "','" & GroupControlNumber & "','" & DocumentDate & "','" & ControlNumber & "','No Comments','N')"
objCmd = New SqlCommand(strSQL, conn)
conn.Open()
objCmd.ExecuteNonQuery()
conn.Close()
End While
objSRFile.Close()
Any advice appreciated...
Thanks,
Lisa