从Excel工作表导入数据,然后使用MVC将其插入到SQL Server中 [英] Import data from Excel sheet and insert it into sql server using MVC
本文介绍了从Excel工作表导入数据,然后使用MVC将其插入到SQL Server中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友们,
我想从excel中读取数据,并且需要对其进行验证并单独使用MVC插入sql服务器数据库中.
我用Google搜寻了很多东西,但对我来说没什么用,SAD MAN.
任何链接或提示都将不胜感激.
在此先感谢.
Hi friends,
I want to read a data from excel and need to validate that and insert into sql server database using MVC alone.
I googled a lot for the thing and nothing works for me, SAD MAN.
Any links or tips are greatly appreciated.
Thanks in advance.
推荐答案
找到Linq表现出色后,我感到放松,
我使用LinqtoExcel库从Excel工作表中读取数据.
将linqtoexcel.dll导入到我的应用程序中,并在控制器中使用此语句,
After finding Linq to excel I felt relax,
I use LinqtoExcel library to read data from the excel sheet.
imported linqtoexcel.dll into my application and use this statement in the controller,
var excel = new ExcelQueryFactory("C:\\Documents and Settings\\rk.prabakar\\Desktop\\test.xlsx");
var dataContent = from c in excel.Worksheet<CheckingAccount>()
select c;
此处是从excel工作表中检索数据并将其存储在datacontent变量中.
Here the data are retrieved from the excel sheet and stored in datacontent variable.
//Checking the datacontent before accessing
if (dataContent != null)
{
//reading content from the excel comes here
foreach (var a in dataContent)
{
userId = Convert.ToInt16(Session["UserId"]);
//a.AccountName is the header row in the excel sheet, which is assigned to accountname variable.
accountName = a.AccountName;
acctDate = a.AccountOpenDate;
currBal = a.CurrentBalance;
//_checkingaccountService.CreateCheckingAccountID(userId, accountName, acctDate, currBal);
//Calling the function from the checking transaction by passing the values.
_checkingtransactionservice.CreateCheckingTransaction(userId, accountName, acctDate, currBal);
currBal.InjectFrom(impfile);
// i++;
}
终于知道了.
Finally I got it.
这篇关于从Excel工作表导入数据,然后使用MVC将其插入到SQL Server中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文