One way is you get all the worksheets of your workbook and after that traverse the workbook and insert your data like:
Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook excelBook = xlApp.Workbooks.Open("D:\\YourWorkbook.xlsx");
foreach (Microsoft.Office.Interop.Excel.Worksheet wSheet in excelBook.Worksheets)
{
cmd.Connection = conn
cmd.CommandText = "INSERT INTO [MS Access;Database=" + DBPath + "].[test] SELECT * FROM [" + wSheet.Name + "]";
}
Second way is, If your worksheets name is same as your database tables then you can get schema of you database and traverse on the tables like:
var excelWorksheets = conn.GetSchema("Tables");
foreach (var row in excelWorksheets.Rows)
{
cmd.Connection = conn
cmd.CommandText = "INSERT INTO [MS Access;Database=" + DBPath + "].[test] SELECT * FROM [" + row["TABLE_NAME"] + "]";
}
Choice is yours. Happy Coding!!