I am reading from a text file in C# using a SQL statement. This is what I am using:
var strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + importFolder + ";Extended Properties=\"text;HDR=No;IMEX=1;FMT=Delimited\"";
var conn = new System.Data.OleDb.OleDbConnection(strconn);
var da = new System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [" + file + "]", conn);
This works fine, but it includes the blank lines at the bottom of the file. Is it possible to make it ignore or disregard the blank lines?
Thanks!
More code:
var importFolder = Path.GetDirectoryName(savedfile);
var file = Path.GetFileName(savedfile);
var strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + importFolder + ";Extended Properties=\"text;HDR=No;IMEX=1;FMT=Delimited\"";
var conn = new System.Data.OleDb.OleDbConnection(strconn);
var da = new System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [" + file + "]", conn);
da.Fill(Exceptions);
I think I would create a new file from the old file using something like this (assuming the file is small enough to fit in memory):
EDIT:
I always forget about this newer method, which bypasses the “small enough to fit in memory” requirement:
ReadLines returns an
IEnumerable<string>; it doesn’t read the whole file into memory.