To parse CSV files using OleDb in C#, you can follow these steps:
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=filepath;Extended Properties=\"Text;HDR=YES;FMT=Delimited\"";
OleDbConnection conn = new OleDbConnection(connectionString);
conn.Open();
string query = "SELECT * FROM [filename.csv]";
OleDbCommand cmd = new OleDbCommand(query, conn);
OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds);
foreach (DataRow row in ds.Tables[0].Rows)
{
Console.WriteLine(row[0].ToString() + " " + row[1].ToString() + " " + row[2].ToString());
}
conn.Close();
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-07-19 07:04:19 +0000
Seen: 17 times
Last updated: Jul 19 '23
In PySpark, how does the lead function work when the value of a column changes?
How can SQL output be structured in a column-based XML format instead of row-based?
How can pgcrypto be used to secure data on Postgres?
What is the SQL grammar used for addSql in Doctrine?
How can Django Admin accommodate a variety of formats and locales for its input fields?