The input string format is incorrect.

Solved
beaulem_5904 Posted messages 10 Status Member -  
 Anonymous user -

I am processing a gedcom file (an editable file with a text editor) to convert it into SQL data. I read the lines of the file and divide the information into different tables. One of these tables accepts a certain number of entries before giving me the error: The input string format is incorrect.

 // reading a line from the gedcom string gedCol1 = ((GedCom)lstGed.Items[i]).colNo1; string gedCol2 = ((GedCom)lstGed.Items[i]).colNo2; string gedCol3 = ((GedCom)lstGed.Items[i]).colNo3; else if(gedCol2 == "NOTE") { gedType = "NOTE"; addNote(gedCol3, lstInIndi); } public void addNote(string note, string numberIndi) { MessageBox.Show("Enter: " + note); bool strFound = false; int j = 0; if(lstDeNote.Items.Count > 0) { /* initialize search */ string l4col1 = ((Note)lstDeNote.Items[j]).numNote; string l4col2 = ((Note)lstDeNote.Items[j]).numIndi; for (j = 0; j < lstDeNote.Items.Count; j++) { /* Iterate through the list to find * the same individual number if found I add the * additional note to the existing note and exit the loop */ if (string.Equals(l4col2, numberIndi)) { strFound = true; ((Note)lstDeNote.Items[j]).txtNote = ((Note)lstDeNote.Items[j]).txtNote + note; return; } /* Initialize next search */ l4col1 = ((Note)lstDeNote.Items[j]).numNote; l4col2 = ((Note)lstDeNote.Items[j]).numIndi; } /* If search is finished and note not found insert the new one */ if (strFound == false) { l4col1 = (j + 1).ToString(); //MessageBox.Show("Note found: " + l4col1 + " : " + note); lstDeNote.Items.Add(new Note { numNote = l4col1, numIndi = numberIndi, txtNote = note }); return; } } else { /* If no note found in the list insert the new one */ if(strFound == false) { lstDeNote.Items.Add(new Note { numNote = "1", numIndi = numberIndi, txtNote = note }); } } }

4 answers

jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention   4 830
 

Hello,

One of these tables accepts a certain number of entries before giving me the error: The input string format is incorrect.

And... have you tried to determine on which line of your file the problem occurred? What is the data in the "wrong" format?


.
Best regards,
Jordane

0
Anonymous user
 

Good evening

 // reading a line from the gedcom string gedCol1 = ((GedCom)lstGed.Items[i]).colNo1; string gedCol2 = ((GedCom)lstGed.Items[i]).colNo2; string gedCol3 = ((GedCom)lstGed.Items[i]).colNo3; else if(gedCol2 == "NOTE") { gedType = "NOTE"; addNote(gedCol3, lstInIndi); }

Why, when it is clear that the list lstGed contains instances of a class called GedCom, with properties corresponding to columns, are you copying the values into strings only to test their value in an else if (without an if beforehand…)

It seems absurd to me.

Wouldn't this be more logical?

 // reading a line from the gedcom GedCom theLine = (GedCom)lstGed.Items[i]); if(theLine.colNo2 == "NOTE") { gedType = "NOTE"; addNote(theLine.colNo3, lstInIndi); }

Furthermore, using a listbox (or another control of that kind) to store your data is poor practice.

Your data should be stored in collections (like list<T> for example) and controls should only be used for display (for example through binding)

And thus, if you had collections, you could make linq queries which are both simpler to code and faster to execute to find the individual to whom you need to add a note.


When I was young, the Dead Sea was just sick.
George Burns

0
beaulem_5904 Posted messages 10 Status Member
 

The line that blocks is: They had 10 children.

0
Anonymous user
 

OK.

But as you can see in the code snippets you posted, we can't see how this line is read from the file or how it is sent to SQL.

And to have a point of comparison, an example of a working line would be nice too.


When I was little, the Dead Sea was just sick.
George Burns

0