Link to home
Start Free TrialLog in
Avatar of sterankin

asked on

Inserting data from Gridview/Datatable into access database

Currently - the user creates and excel spreadsheet on their desktop with some data, then uses the ASP.NET web app to upload the excel spreadsheet.  The data is read in from the spreadsheet and put into a DataTable which is then bound to a gridview for the user to see and verify.

I then want to be able to insert the data from the datatable into an Access DB (the columns should match).

How do I do this?  Is there a simple way to Insert the datatable or the rows from the datatable into the access database?
Access table: TestTable
Columns:  Column1, Column2, Column3, Column4 etc  
Avatar of Reecio

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sterankin


I will look into that thanks - I read there may be a way to do it with a DataAdapter, or a bulk update?  But I have not found any details on this...
However, that is for data in a gridview, but if you load the data in to a gridview that you have made invisible you might be able to pull off the same effect?

Otherwise looping for each row is the only other way I can think of, in fact, the control basically does that, as on rowdatabound is activated when a row is bound to the control.
Reecio - I had a look at that link to msdn, but I am not sure how this would work with the excel file.

Basically I am loading data from an excel file to the gridview.  I then want to insert all the rows into an access database.

Is the only way to do this by using a loop?
I know there is a way to insert in bulk but via SQL statements, so i'm not sure how to best implement it with this exercise. I have found a bulk insert statement that uses stored procedures (;EN-US;316244) but dont think there is an easy way to do it just in code unless via a loop.