将Excel工作表上传到sql表中,而在asp.net中没有重复项 [英] upload an excel sheet into sql table without duplicates in asp.net

查看:82
本文介绍了将Excel工作表上传到sql表中,而在asp.net中没有重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在将Excel工作表上传到sql表中.
我想上传没有重复的数据.
如果表中已经存在数据,则应该更新表.
如果表中不存在数据,则应在表后追加.
请说出解决方案.
我尝试了很多代码..全部失败了...

Hi,
I am uploading an excel sheet into sql table.
I want to upload a data without duplicates.
If the data already exists in the table, that should update the table.
If the data doesn''t exists in the table, then that should append the table.
Kindly say the solution for it.
I tried with many codes..All flopped...

推荐答案

IF EXISTS(SELECT * FROM table WHERE id1 = @id)
  BEGIN
     -- do the update because you know it exists
     UPDATE Table SET field1 = @field1, etc.
  END
ELSE
  BEGIN
    -- do an insert, because it does not exist
    INSERT INTO table ...
  END


这篇关于将Excel工作表上传到sql表中,而在asp.net中没有重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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