将数据从excelsheet上传到SQL数据库 [英] Upload data from excelsheet to SQL database

查看:110
本文介绍了将数据从excelsheet上传到SQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Guys,



我有一个客户项目,客户要求是他想在Excel中使用网页将数据从Excel工作表上传到Sql数据库.net c#



我知道如何将数据从Excel工作表上传到Sql DB表,但问题是(?) - 假设第一次客户端从上传10条记录1张到Sql Db和第二次客户端以及更多5条记录在Excle-Sheet所以总记录是15然后客户端上传记录然后我已经有10条旧记录和这个新的15条记录上传然后总共25条记录插入Sql Db但我需要只上传最后添加的5条记录到Sql Db,并且客户端在第一条记录中进行了更改,然后它也会在Sql DB中更新。

那么如何以最佳方式管理或同步数据库



技术:Asp.net 4.0 / 4.5,C#,Sql Server





谢谢...



我尝试过:



大家好,



我已经从Excel Sheet到Sql Database进行了简单的上传数据,但是每次我上传相同的Excel工作表数据时都要添加和更新,那么应该保留现有数据的效果。 sql数据库和所有excel数据作为新条目插入所以我想要同时执行更新和新添加。

Hello Guys,

I have one project of client and client's requirement is that he want to upload data from Excel-sheet to Sql Database using web page in asp.net c#

I know simple how to upload data from Excel-sheet to Sql DB table but Question is that(?) - Suppose 1st time client upload 10 record from 1 sheet to Sql Db and 2nd time client and more 5 record in Excle-Sheet so total record is 15 and then client upload record then I have already 10 old record and this new 15 record upload then total 25 record inserting in Sql Db but I need to upload only last added 5 records only into Sql Db and also client made changes in 1st record then it also be updated in Sql DB.
So how it possible in best way for manage or sync Database

Technology : Asp.net 4.0/4.5, C#, Sql Server


Thanks...

What I have tried:

Hello Guys,

I have do simple upload data from Excel Sheet to Sql Database but every time I upload same Excel sheet data with addition and updation then effect should be done with exist data remain as it is in sql database and all excel data inserting as new entry so I want to as both updation and new addition should be perform.

推荐答案

试试这个:-) 使用ASP.Net C将Excel文件记录插入SQL Server数据库# [ ^ ]
Try this :-) Inserting Excel File Records Into SQL Server Database Using ASP.Net C#[^]


如果客户端坚持要再次在工作表中上传记录,那么您有几个选项。



1)第一个是SQL批量复制。我根本不会建议您使用这种方法。您可以做的是清除已经上传的数据,只使用批量复制将所有内容作为新内容插入。这个问题你可以放松与其他表的关系。我再也不会推荐这个。



2)你可以循环遍历excel文档的每一行并检查SQL中是否已经存在该行,如果是这样,那么更新记录,如果没有插入新记录。
You have a couple of option if the client insist on having records that have already been uploaded in the sheet again.

1) The first is SQL Bulk Copy. I would not recommend this method for your requirements at all. What you could do is wipe out the data that is already upload and just use bulk copy to insert everything as new. The problem with this you can loose relationships with other tables. Again I would not recommend this at all.

2) You can loop through each line of the excel document and check if the row already exist in SQL and if so update the record if not insert the new record.


这篇关于将数据从excelsheet上传到SQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆