Im reading a text file that consists of thousands of codes but the order of the code is as follows.
First line: NS10 EW9
Second line: $1.91
Third line: $2.60
Fourth line: 42
Im trying to split the first line into two seperate lines in the new list.
I Modified my code but there still is another error. It is an index out of range exception error.
int size = FaresFile.Length / 4 * 5;
int linecount = 0;
String[] split = new string[size];
conn.ConnectionString = "Data Source=***\\*** database=***; integrated security= true";
do
{
split = FaresFile[0].Split(' ');
cmd.CommandText = string.Format("INSERT INTO Fares Values ('{0}','{1}', '{2}', '{3}', '{4}' )", split[linecount], split[linecount + 1], split[linecount + 2], split[linecount + 3], split[linecount + 4]);
cmd.Connection = conn;
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
}
finally
{
conn.Close();
}
linecount = linecount + 5;
}while(linecount != split.Length);
I expected the new list to look like this.
First line: NS10
Second line: EW9
Third line: $1.91
Fourth line: $2.60
Fifth line: 42
I cannot run the program as there is an error in the code.