The input string format is incorrect.
SolvedAnonymous 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 }); } } }
- An object reference is required.
- How to insert the square root symbol
- Quelle est la dénomination des machines qui détectent les prix des produits ?
- Visual Studio Error: Unable to load the file or assembly
- Object reference not set to an instance of an object
- Calculate the records of a datagridview one by one.
4 answers
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
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