Luke Luke - 1 month ago 24
C# Question

Import txt file data into datagridview c#

I am trying to import data into my datagridview. The code I have so far is:

private void loadButton_Click(object sender, EventArgs e)
if (File.Exists(DATA_FILE_NAME))
fileIn = File.OpenText(DATA_FILE_NAME);
MessageBox.Show(DATA_FILE_NAME + " does not exist", "Abort Execution", MessageBoxButtons.OK, MessageBoxIcon.Error);
if (listCountTextBox.ReadInt(out index))
for (int i = 1; i <= index; i++)
idList.Add(Int32.Parse(fileIn.ReadLine())); <----- Error here

The format of the data in the text file looks like this: "000-0000" and there are 1,240,000 values. The error says: Input string was not in a correct format.
Any help would be much appreciated!

Thank You!


As the others responds is not posible to convert "000-0000" to int, thats the error.

Would work if you change:

//idList.Add(Int32.Parse(fileIn.ReadLine())); <----- Error here