Free Support Forum -

Save data to database

Hi <br><br>I have purchased ASPOSE Total. I am not sure where to get the demo for reading data from an excel sheet and saving it to my database. Could you please provide the code required.<br><br>Regards<br>Shalini<br>
Hi Shalini,

Thanks for considering Aspose.

Well, you may read data from worksheet of a workbook and export it to fill a datatable using Aspose.Cells APIs (Cells.ImportDataTable / Cells.ImportDataTableAsString methods) and use your own ADO.NET code to save it to your data source. Alternatively, you may export data to an array and later save it in your database.

May the following code help your need:

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
DataTable dataTable = new DataTable();
dataTable = worksheet.Cells.ExportDataTableAsString(0, 0, worksheet.Cells.MaxRow + 1, worksheet.Cells.MaxColumn + 1);
dataGrid1.DataSource = dataTable;

For further reference, please check wiki documentation ( especially the topic:

Thank you.

what do we need to include to define FileStream. now it gives the message - filestream not define.


I am not very clear your need. However, I write the following code for my understanding. Kindly make sure that you have referenced System.IO namespace in your project.


FileStream fs = new FileStream("d:\\test\\mybook.xls",FileMode.Open);
Workbook workbook =new Workbook();

Thank you.