link

Hi there

I'm trying to import a formatted file into my MySQL database. For those familiar, its a BibTeX file. I have no problem importing any data but, whatever I have tried so far, I can't seem to figure out a way for the same record to be input twice.

To explain further, here's my code:

StringBuilder details = new StringBuilder(); StreamReader str = new StreamReader(fileName); 
using (StreamReader sr = File.OpenText(fileName))
{
String input;
while ((input = sr.ReadLine()) != null)
{
string line = str.ReadLine();
if (line.Trim() == "}")
{
AddBibTexRecord(prop);
AllPropClear();
}
else if (line.Contains("@article"))
{
prop = new PaperProperties();
prop = ArticleProcess(fileName);
}

// extra statements omitted
}
}
}



So, what I'm trying to do is to store all the attributes of a BibTeX record into an Entity class called PaperProperties then, when we reach the end of a single BibTeX record, import that collection of variables as a record.

After doing this (importing a single record), initially, I coded a method to make all the strings empty before looking for another record within the file

That didn't work so, I tried to create a new object before importing the data, that still duplicated the entry as well.

Finally, assuming that StreamReader has to be told that we're not just reading a clunk of data, but all the text within a file, I found the statement:

using (StreamReader sr = File.OpenText(fileName))


in a sample online. That hasn't worked either.

For anyone who has had the patience to read this post, do you know any libraries that would help me solve this problem and avoid duplicate entries?

Cheers
Matt