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.IndexOut OfRangeExceptio n: 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 ConnectionStrin g As String = "Data
Source=localhos t;Integrated Security=SSPI;I nitial Catalog=DEVTEST "
Dim Con As New SqlConnection(C onnectionString )
Dim CmdInsert As New SqlCommand("INS ERT 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.OpenSta ndardOutput()
Console.WriteLi ne(args(0))
FileOpen(1, args(0), OpenMode.Input, OpenAccess.Read ,
OpenShare.Defau lt)
Do Until EOF(1)
LineOfText = LineInput(1)
AllText = AllText & LineOfText & vbCrLf
LineArray = Split(LineOfTex t, ",")
Con.Open()
Dim BatchQuery As String = "INSERT INTO DEVTEST (ID,
TESTVAL1, TESTVAL2) VALUES (" & LineArray(0) & ", '" & LineArray(1) &
"' , '" & LineArray(2) & "')"
Dim Cmd As New SqlCommand(Batc hQuery, Con)
Dim Adapter As New SqlDataAdapter( Cmd)
Cmd.CommandType = CommandType.Tex t
Cmd.ExecuteNonQ uery()
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.IndexOut OfRangeExceptio n: 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 ConnectionStrin g As String = "Data
Source=localhos t;Integrated Security=SSPI;I nitial Catalog=DEVTEST "
Dim Con As New SqlConnection(C onnectionString )
Dim CmdInsert As New SqlCommand("INS ERT 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.OpenSta ndardOutput()
Console.WriteLi ne(args(0))
FileOpen(1, args(0), OpenMode.Input, OpenAccess.Read ,
OpenShare.Defau lt)
Do Until EOF(1)
LineOfText = LineInput(1)
AllText = AllText & LineOfText & vbCrLf
LineArray = Split(LineOfTex t, ",")
Con.Open()
Dim BatchQuery As String = "INSERT INTO DEVTEST (ID,
TESTVAL1, TESTVAL2) VALUES (" & LineArray(0) & ", '" & LineArray(1) &
"' , '" & LineArray(2) & "')"
Dim Cmd As New SqlCommand(Batc hQuery, Con)
Dim Adapter As New SqlDataAdapter( Cmd)
Cmd.CommandType = CommandType.Tex t
Cmd.ExecuteNonQ uery()
Con.Close()
Loop
End Sub
End Module
*************** *************** *************** *************** *************** *************** *************** ***
Thanks,
David B.
Comment