Here is my solution to show data from Excel in gridview.
'Load Workbook
Dim workbook As Workbook = New Workbook()
workbook.LoadFromFile(Page.MapPath("./Data/Sample.xls"), True)
'Initialize Worksheet
Dim sheet As Worksheet = workbook.Worksheets(0)
'Export Data to DataTable and Bind Data to GridView
Dim table As DataTable = sheet.ExportDataTable
Me.GridView1.DataSource = table
Me.GridView1.DataBind()
I use a commercial
ASP.NET Excel library in this solution. Hope helpful!
or ellse make the complete data into a Xml format, then send it to a stored procedure...in the stored procedure you can hace OpenXml in TSQL to make bulk inserts...
adejoya
Member
2 Points
29 Posts
How to Upload an Excel file to a GridView and save it to database. (VB)
Mar 05, 2013 06:53 AM|LINK
I can upload an Excel File and make it a gridview, but what i want to do is, insert the data also into my database that comes from the gridview.
Thanks.
pon_prabhu
Participant
828 Points
185 Posts
Re: How to Upload an Excel file to a GridView and save it to database. (VB)
Mar 05, 2013 06:56 AM|LINK
http://www.codeproject.com/Questions/444131/how-to-import-excel-sheets-in-asp-net
http://forums.asp.net/t/1336761.aspx/1
Sharon59
Member
180 Points
31 Posts
Re: How to Upload an Excel file to a GridView and save it to database. (VB)
Mar 06, 2013 08:01 AM|LINK
Hello,
Here is my solution to show data from Excel in gridview.
'Load Workbook Dim workbook As Workbook = New Workbook() workbook.LoadFromFile(Page.MapPath("./Data/Sample.xls"), True) 'Initialize Worksheet Dim sheet As Worksheet = workbook.Worksheets(0) 'Export Data to DataTable and Bind Data to GridView Dim table As DataTable = sheet.ExportDataTable Me.GridView1.DataSource = table Me.GridView1.DataBind()I use a commercial ASP.NET Excel library in this solution. Hope helpful!
ramiramilu
All-Star
97799 Points
14494 Posts
Re: How to Upload an Excel file to a GridView and save it to database. (VB)
Mar 06, 2013 12:13 PM|LINK
SqlBulkCopy is one way -
http://csharpdotnetfreak.blogspot.com/2009/04/export-excel-data-sqlbulkcopy-aspnet.html
or ellse make the complete data into a Xml format, then send it to a stored procedure...in the stored procedure you can hace OpenXml in TSQL to make bulk inserts...
thanks,
JumpStart
karang
Contributor
2475 Points
922 Posts
Re: How to Upload an Excel file to a GridView and save it to database. (VB)
Mar 06, 2013 01:32 PM|LINK
To upload excel into database see this link
http://gyansangrah.com/ArticleContent.aspx?ID=bulk_upload_in_asp_net
Once data goes into the database, you can get data using SQLConnection, SQLCommand and SQLDataAdapter class and bind using following code
gvYourGrid.DataSource = dataset_or_datatable_or_collection;
gvYourGrid.DataBind();
Karan Gupta
http://gyansangrah.com
Please click "Mark as Answer" if this helped you.
farooque84
Participant
1358 Points
321 Posts
Re: How to Upload an Excel file to a GridView and save it to database. (VB)
Mar 06, 2013 01:38 PM|LINK
Hi,
Use below code to load the values to grid while importing excel ,
http://www.aspdotnet-suresh.com/2012/12/how-to-import-data-from-excel-to-aspnet.html
Use below code to save the loaded gridview values in to database,
http://www.c-sharpcorner.com/blogs/8387/insert-data-from-gridview-to-database.aspx