1

I need some help we are going to import the data from excel to mysql database and we're going to use the MS Interop. We don't know how to start and we do some research about the MS Interop but we don't know how to start. We only now is declare the namespace we don't know what's next.

We found some youtube tutorials but they are using OLedb(if this is right), I hope you can help us!

rene
  • 41,474
  • 78
  • 114
  • 152
Michelle
  • 23
  • 1
  • 6
  • Are you sure you need interop? There are easier ways if you're working with .xlsx files. – Crowcoder Sep 17 '17 at 10:42
  • Why? Is there another way to do it? – Michelle Sep 17 '17 at 11:00
  • You can use the OpenXML SDK, or an abstraction of it like the ClosedXML library. I believe there's another one called Epplus. – Crowcoder Sep 17 '17 at 11:04
  • I've searched about the OpenXML is this only for creating an excel file? I don't see instruction for importing or something.. – Michelle Sep 17 '17 at 11:14
  • It is a complete SDK for MS Office files. It can be complicated, ClosedXML is an abstraction over it to make it easier. You can still do most anything with Excel and [there are a lot of examples](https://github.com/closedxml/closedxml/wiki#examples). – Crowcoder Sep 17 '17 at 11:23

1 Answers1

2

You can use ExcelDataReader or Microsoft.Office.Interop.Excel as described in this answer, to read data from your sheet, then create a SqlCommand, like insert into myTable (column1, column2) values (1, 'mydata') and execute it over a connection to your MySQL Database.

shA.t
  • 16,580
  • 5
  • 54
  • 111