且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将Excel数据插入SQL Server表

更新时间:2022-11-28 13:57:03

假定您已将文件中的数据读入某种类型的集合中,例如List< empdata&gt ;,其中EmpData是您的对象我会做的(几乎是伪代码):

Assuming you have read the data from the file into some sort of collection say List<empdata>, where EmpData is your object here is what I would do (in almost pseudocode):

List<empdata> emps = ParseExcelData();
foreach(EmpData emp in emps)
{
   //if this emp doesn't exist in the DB already, the function would return null
   //but if its not null, then it will just skip and move to next record repeating    the same process
   if (GetEmpDataFromDatabaseById(emp.Emp_ID) == null )
   {
      SaveEmpData(emp);
   }
}</empdata>



您将必须编写自己的ParseExcelData,GetEmpDataFromDatabaseById和SaveEmpData方法.

希望这会有所帮助.

干杯.



You would have to write your own ParseExcelData, GetEmpDataFromDatabaseById and SaveEmpData methods.

Hope this helps.

Cheers.