Click here to Skip to main content
15,888,297 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an excel table that contains 3 columns but contains a variable number of rows.
And I want to insert this excel table into rows and columns that are the same as the database table.I would like to import the database by selecting the Excel file.But I wasn't successful.
I'm waiting for your help on this.

My process steps are as follows.

1.Excel selection (Done)
2. Read the selected option. (reads in foreach but does not write)
3. Insert the rows and columns in the same way into the table structure. (Not done)

What I have tried:

//Insert button action method
private void ExcelImport(object obj){
    Excel.Application app=new Excel.Application();
    Excel.Workbook workbook=app.workbooks.Open(fileName,Type.Missing,Type.Missing);
    Excel.Worksheet sheet=workbook.Sheets[1];
    Excel.Range range=sheet.UsedRange;

  
}
Posted
Updated 9-Jun-19 17:57pm
v2
Comments
Richard MacCutchan 5-Jun-19 3:24am    
I explained once already how to do this, but I guess you have deleted the question. Also why are you using the Excel Interop to open the file and then OLEDB to read it?

1 solution

First off, Excel isn't a database, and really, really shouldn't be considered as one: it has a "row / column" structure, but it's a flat file and does not respond well to being treated as a DB - if nothing else, performance will be terrible.

But if you are only interested in reading data from your Excel file, I'd strongly suggest you use this: C# How To Read .xlsx Excel File With 3 Lines of Code[^] instead of using OleDb
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900