Last active
June 8, 2016 07:11
-
-
Save sir4ju1/f0f41201ed2e7ce84223 to your computer and use it in GitHub Desktop.
Read CSV of collection of DSE Data and write to SQLite using ORMLITE
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
String path = HttpContext.Current.Server.MapPath(@"~\App_Data\all_files\"); | |
var d = new DirectoryInfo(path); //Assuming Test is your Folder | |
FileInfo[] Files = d.GetFiles("*.csv"); //Getting Text files | |
var sb = new StringBuilder(); | |
var dbFactory = new OrmLiteConnectionFactory(SqliteFileDb, false, SqliteDialect.Provider); | |
using (IDbConnection db = dbFactory.Open()) | |
{ | |
db.CreateTableIfNotExists<ModelQuote>(); | |
List<ModelQuote> quotes = new List<ModelQuote>(); | |
foreach (FileInfo file in Files) | |
{ | |
var values = File.ReadAllLines(file.FullName).Where(arg => !string.IsNullOrWhiteSpace(arg)).ToList(); | |
values.RemoveAt(0); | |
foreach (var q in values) | |
{ | |
var qs = q.Split(','); | |
var qt = new ModelQuote(); | |
qt.Code = Path.GetFileNameWithoutExtension(file.Name); | |
qt.TradeDate = DateTime.Parse(qs[0]); | |
qt.Open = qs[1].ToFloat(); | |
qt.High = qs[2].ToFloat(); | |
qt.Low = qs[3].ToFloat(); | |
qt.Close = qs[4].ToFloat(); | |
qt.Volume = qs[5].ToInt(); | |
quotes.Add(qt); | |
} | |
//list.Add(qt); | |
} | |
using (var tran = db.OpenTransaction()) | |
{ | |
db.Insert(quotes.ToArray()); | |
tran.Commit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment