Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Dataset to Access DB
    primarykey
    data
    text
    <p>I have a dataset that is dynamically created from a csv file. What I want to do is insert the rows into my MS Access table but I cannot figure out where to start with this. </p> <p>The headers of the data in the dataset can vary as far as the order but the name of the header will always match the access database. Do I have to statically call out the header name in the insert command or can I build the headers from the dataset?</p> <p>I know how to create the connection and open it to the database but am not sure how to create in insert command to dynamically pull the table headers.</p> <p>I am pretty green when it comes to C# programming so if you can spell it out for me I would really appreciate it!</p> <p>Here is an example of the access table headers:</p> <p>ID, Item, Cost, Retail</p> <p>Then the CSV which will fill the dataset table. It might have Retail or it might not:</p> <p>Item, Cost</p> <p>Here is the code I have so far but it doesn't write to the access table. If I vew the dtAccess it shows correctly.</p> <pre><code> OleDbConnection myConnection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\"C:\\Database.accdb\";Persist Security Info=False;"); myConnection.Open(); string queryString = "SELECT * from " + lblTable.Text; OleDbDataAdapter adapter = new OleDbDataAdapter(queryString, myConnection); DataTable dtAccess = new DataTable(); DataTable dtCSV = new DataTable(); dtCSV = ds.Tables[0]; using (new OleDbCommandBuilder(adapter)) { adapter.Fill(dtAccess); dtAccess.Merge(dtCSV); adapter.Update(dtAccess); } myConnection.Close(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload