Skip to content

Instantly share code, notes, and snippets.

@SIRHAMY
Created August 8, 2018 15:35
Show Gist options
  • Save SIRHAMY/45833888c8337a1e07b252881b912c95 to your computer and use it in GitHub Desktop.
Save SIRHAMY/45833888c8337a1e07b252881b912c95 to your computer and use it in GitHub Desktop.
LinqPad (C#) CSV Parser
// readPath goes here
const string licenseCsvPath = @"C:\some\path";
// writePath goes here
const string writeSqlpath = @"C:\some\path";
var sqlString = new StringBuilder();
sqlString.Append(
@"INSERT INTO dbo.myTable
(userId, nameId, disableUsernamePassword)
VALUES
");
// Read in License CSV
using (var reader = new StreamReader(licenseCsvPath))
{
// Skip header row
reader.ReadLine();
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(',');
var columnZero = values[0].Trim();
var column4 = values[4].Trim();
var column6 = values[6].Trim();
// Insert values here
sqlString.Append("");
}
}
File.WriteAllText(writeSqlpath, sqlString.ToString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment