Skip to content

Commit

Permalink
Move things around
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Nov 21, 2024
1 parent 0cc1a4b commit 2b11863
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,7 @@ public CsvDataSourceAttribute(string fileName)
throw new FileNotFoundException($"Csv file '{fullPath}' cannot be found.", fullPath);
}

string tableName = Path.GetFileName(fullPath).Replace('.', '#');

// We can map simplified CSVs to an OLEDB/Text connection, then proceed as normal
using OleDbConnection connection = new();
using OleDbDataAdapter dataAdapter = new();
using OleDbCommandBuilder commandBuilder = new();
using OleDbCommand command = new();

// We have to use the name of the folder which contains the CSV file in the connection string
// If target platform is x64, then use CsvConnectionTemplate64 connection string.
Expand All @@ -56,13 +50,20 @@ public CsvDataSourceAttribute(string fileName)
// The connection will get closed when we dispose of it
connection.Open();

using OleDbCommandBuilder commandBuilder = new();
string tableName = Path.GetFileName(fullPath).Replace('.', '#');
string quotedTableName = commandBuilder.QuoteIdentifier(tableName, connection);

command.Connection = connection;

command.CommandText = $"SELECT * FROM {quotedTableName}";
using OleDbCommand command = new()
{
Connection = connection,
CommandText = $"SELECT * FROM {quotedTableName}",
};

dataAdapter.SelectCommand = command;
using OleDbDataAdapter dataAdapter = new()
{
SelectCommand = command,
};

DataTable table = new()
{
Expand Down

0 comments on commit 2b11863

Please sign in to comment.