D
David B
I am writing a console App with VB 2005 where I accept a text file as
input, parse it and insert the text data into an SQL table. I have
written the code correctly as well as I can tell because it works
running it within the IDE, given that you have to go into the Debug
Project Properties to specify the argument. If I build the file and go
run it from the command line, specifying the argument, I get the
following error:
C:\>devtest.exe devtest.txt
devtest.txt
Unhandled Exception: System.IndexOutOfRangeException: Index was outside
the boun
ds of the array.
at DEVTEST.Module1.Main(String[] args)
Note, for debugging purposes, I write to the console the first element
of the args() array. I don't see how the index is outside the bounds
of the array especially when it works fine within the IDE. If anyone
has any ideas, any suggestions would be helpful. I am writing and
running this from VB 2005 Express. Below is my full code:
***********************************************************************************************************
Module Module1
Dim LineOfText As String
Dim AllText As String
Dim LineArray(3) As String
Private ConnectionString As String = "Data
Source=localhost;Integrated Security=SSPI;Initial Catalog=DEVTEST"
Dim Con As New SqlConnection(ConnectionString)
Dim CmdInsert As New SqlCommand("INSERT INTO DEVTEST (ID, PO_NAME,
AMOUNT) VALUES ('123', 'TEST', '123.32')", Con)
Dim args(2) As String
Public Sub Main(ByVal args() As String)
Console.OpenStandardOutput()
Console.WriteLine(args(0))
FileOpen(1, args(0), OpenMode.Input, OpenAccess.Read,
OpenShare.Default)
Do Until EOF(1)
LineOfText = LineInput(1)
AllText = AllText & LineOfText & vbCrLf
LineArray = Split(LineOfText, ",")
Con.Open()
Dim BatchQuery As String = "INSERT INTO DEVTEST (ID,
TESTVAL1, TESTVAL2) VALUES (" & LineArray(0) & ", '" & LineArray(1) &
"' , '" & LineArray(2) & "')"
Dim Cmd As New SqlCommand(BatchQuery, Con)
Dim Adapter As New SqlDataAdapter(Cmd)
Cmd.CommandType = CommandType.Text
Cmd.ExecuteNonQuery()
Con.Close()
Loop
End Sub
End Module
************************************************************************************************************
Thanks,
David B.
input, parse it and insert the text data into an SQL table. I have
written the code correctly as well as I can tell because it works
running it within the IDE, given that you have to go into the Debug
Project Properties to specify the argument. If I build the file and go
run it from the command line, specifying the argument, I get the
following error:
C:\>devtest.exe devtest.txt
devtest.txt
Unhandled Exception: System.IndexOutOfRangeException: Index was outside
the boun
ds of the array.
at DEVTEST.Module1.Main(String[] args)
Note, for debugging purposes, I write to the console the first element
of the args() array. I don't see how the index is outside the bounds
of the array especially when it works fine within the IDE. If anyone
has any ideas, any suggestions would be helpful. I am writing and
running this from VB 2005 Express. Below is my full code:
***********************************************************************************************************
Module Module1
Dim LineOfText As String
Dim AllText As String
Dim LineArray(3) As String
Private ConnectionString As String = "Data
Source=localhost;Integrated Security=SSPI;Initial Catalog=DEVTEST"
Dim Con As New SqlConnection(ConnectionString)
Dim CmdInsert As New SqlCommand("INSERT INTO DEVTEST (ID, PO_NAME,
AMOUNT) VALUES ('123', 'TEST', '123.32')", Con)
Dim args(2) As String
Public Sub Main(ByVal args() As String)
Console.OpenStandardOutput()
Console.WriteLine(args(0))
FileOpen(1, args(0), OpenMode.Input, OpenAccess.Read,
OpenShare.Default)
Do Until EOF(1)
LineOfText = LineInput(1)
AllText = AllText & LineOfText & vbCrLf
LineArray = Split(LineOfText, ",")
Con.Open()
Dim BatchQuery As String = "INSERT INTO DEVTEST (ID,
TESTVAL1, TESTVAL2) VALUES (" & LineArray(0) & ", '" & LineArray(1) &
"' , '" & LineArray(2) & "')"
Dim Cmd As New SqlCommand(BatchQuery, Con)
Dim Adapter As New SqlDataAdapter(Cmd)
Cmd.CommandType = CommandType.Text
Cmd.ExecuteNonQuery()
Con.Close()
Loop
End Sub
End Module
************************************************************************************************************
Thanks,
David B.