如何在C#中将excel导入数据库?(How to import excel to database in C#?)

272 IT屋

ID   NAME    CLASS

  86    Kelvin    4  

  59    Johny     7




I would like to read the value of excel and set datagrid and insert it into the same table.
When I click on the save button in MVVM excelde any field is empty if there is no record of the error if I want to be written in the datagride.
How can I do it.

What I have tried:

//Excel Read Code

    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;

    DataTable dt=new DataTable();
    int col =range.Columns.Count;
    int row= range.Rows.Count;
解决方案
Working with Excel Using C#[^]
Have you tried looking there?

 ID NAME CLASS 

86 Kelvin 4

59 Johny 7


< br $> b $ b



我想读取excel的值并设置datagrid并将其插入到同一个表中。

当我点击MVVM excelde中的保存按钮时,如果我想在datagride中写入没有错误记录,则任何字段都是空的。

我该怎么做。



我尝试过:



 // Excel读取代码

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;

DataTable dt = new DataTable();
int col = range.Columns.Count;
int row = range.Rows.Count;
解决方案
使用C#使用Excel [ ^ ]

你试过看那里吗?

本文地址:IT屋 » 如何在C#中将excel导入数据库?