Created
August 8, 2018 15:35
-
-
Save SIRHAMY/45833888c8337a1e07b252881b912c95 to your computer and use it in GitHub Desktop.
LinqPad (C#) CSV Parser
This file contains hidden or 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
// 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