2
Answers

Index was outside the bounds of array

Ask a question
Hi, I'am trying to import a Text file which is delimited by a 'Tab Space ' into my database . Everything works until i try to give the insert myCommand.CommandText = "INSERT INTO SYS_PARTS VALUES ('" & fields(0) & "', '" & fields(1) & "', '" & fields(2) & "', '" & fields(3) & "', '" & fields(4) & "', '" & fields(5) & "', '" & fields(6) & "', '" & fields(7) & "','" & fields(8) & "','" & fields(9) & "','" & fields(10) & "','" & fields(11) & "','" & fields(12) & "','" & fields(13) & "','" & fields(14) & "','" & fields(15) & "','" & fields(16) & "','" & fields(17) & "')" If i try to print the data using console.writeline , it prints me the data correctly Console.WriteLine("INSERT INTO SYS_PARTS VALUES ('" & fields(0) & "', '" & fields(1) & "', '" & fields(2) & "', '" & fields(3) & "', '" & fields(4) & "', '" & fields(5) & "', '" & fields(6) & "', '" & fields(7) & "','" & fields(8) & "','" & fields(9) & "','" & fields(10) & "','" & fields(11) & "','" & fields(12) & "','" & fields(13) & "','" & fields(14) & "','" & fields(15) & "','" & fields(16) & "','" & fields(17) & "')") This consoled Output , if i try to insert into the table , the record gets inserted without giving any error ,but if i try to do usin mycommand.commandtext and myCommand.ExecuteNonQuery() , it shows me this error Index was outside the bounds of array

Answers (2)