如何在C#中将Excel导入数据库? [英] How to import excel to database in C#?
本文介绍了如何在C#中将Excel导入数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ID NAME CLASS
86 Kelvin 4
59 Johny 7
我想读取excel的值并设置datagrid并将其插入到同一表中.
当我单击MVVM excelde中的保存按钮时,如果我想写入datagride,则如果没有错误记录,则任何字段为空.
我该怎么办.
我尝试过的事情:
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;
推荐答案
使用C#使用Excel [ ^ ]
您尝试过看那里吗?
Working with Excel Using C#[^]
Have you tried looking there?
这篇关于如何在C#中将Excel导入数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文