Created
April 20, 2010 19:52
-
-
Save nickcharlton/372971 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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