Skip to content

Instantly share code, notes, and snippets.

@nickcharlton
Created April 20, 2010 19:52
Show Gist options
  • Save nickcharlton/372971 to your computer and use it in GitHub Desktop.
Save nickcharlton/372971 to your computer and use it in GitHub Desktop.
public string Import()
{
/*
* This is an example of how to import the MealDeliveries.txt file provided with SOFT130
*
* It loads the text file into an SQLite Database
*
*/
// define variables we'll use
int counter = 0;
int queryCount = 0;
string line;
string query = "";
// Read the file
StreamReader fileRead = new StreamReader(file);
while ((line = fileRead.ReadLine()) != null)
{
// on every 7 items, build a new query.
if (counter % 7 == 0)
{
query = query + "INSERT INTO orders (name, location, day, time, option, note, status) VALUES(";
}
query = query + "'" + line + "'";
queryCount++;
if (queryCount == 7)
{
query = query + "); ";
queryCount = 0;
}
else
{
query = query + ", ";
}
counter++;
}
fileRead.Close();
return query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment