将Excel数据导入并更新到sql中(Import and Update Excel data into sql)

   IT问题网   2021-01-21 00:00:00

问 题

嗨,

我正在研究一个将数据导入sqlserver的项目,我已经编写sp用于插入但同时我需要更新sql server中的数据

i已编写样本sp,sp正在插入并更新excelsheet中的最后一行,我需要将数据从excelsheet导入到sql并需要更新sqlserver中的数据



sample sp



  create   proc  [dbo]。[convertchartobinary1]( @ value   varchar  8000 ))
as
begin
声明 @ flag int ;

if exists select *来自[dbo] .table1)
开始
set @ flag = 1 ;
end
else
开始
set @ flag = 0 ;
end
if @ flag = 0
开始
插入 进入 [dbo] .table1([char_c])(演员表(cast( @ value as char 8000 )) as binary 8000 )))
结束
其他
开始
更新 table1 set [char_c] =(强制转换(强制转换( @ value as char
4000 )) as 二进制 4000 )))
结束
结束
go

解决方案

调用存储过程,如果数据已存在则需要更新,如果不存在则需要插入。

  if   exists  select  *  from  table1  where  column1 = '  somevalue'
更新表1 set (...) where column1 = ' somevalue'
else
insert into 表1 values (...)








上述问题的解决方案



create proc [dbo ]。[convertchartobinary1](@ value3 varchar(8000),@ value1 varchar(8000))

as



开始

if exists(select * from [dbo] .table1 where [int_c] = convert(binary,cast(@ value3 as int)))



update table1 set [int_c] = convert(binary,cast(@ value3 as int)),

[char_c] =(cast(强制转换(@ value1 as char(4000))为binary(4000)) )where [int_c] = convert(binary,cast(@ value3 as int))





else





插入[dbo] .table1([int_c],[char_c])值



convert(binary,cast(@ value3 as int)),

cast(cast(@ value1 as char(5) 0))二进制(50))









结束

go

标签:数据导入更新



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

如何在asp中使用我的sql(How to use my sql in asp)

problem hi sir/madam, in our application of asp,we have ...

如何制作wpf鼠标事件?(How can made wpf mouse event )

problem how can made wpf mouse event see more: c# please ...

如何在包含三个用于用户输入的asp.net服务器控件的表中动态添加行(how to add rows dynamically in the table containing three asp.net server controls for user input)

problem hi a table having 5 rows and 3 columns, each ro ...

如何将string []数组值分配给cookie(How to assign a string[] array values to a cookie)

problem i have a string array and it is filling by databa ...

在基本MSI项目中从InstallShield显示消息“安装程序需要64位处理器”(Show message “Setup requires a 64Bit processor” from InstallShield in basic MSI project)

problem i am using installshield 11 and creat ...

c ++编程语言(c++ programming language)

problem hello all, i am looking to design c++ code for is ...

MySql DB(如何在部署时添加DB)(MySql DB(how to add DB at the time of deployment))

problem hello, i am going to deploy(c#.net with mysql 5.0 ...

如何为15个链接按钮单击事件实现相同的代码(How to implement same code for 15 linkbutton click events)

problem hi, i want to bind a tree in horizon ...

在数据网格中更改字段的名称(change field's name in a datagrid)

problem how can i change name of the each header columns ...

使用多个mdi表单(working with mutiple mdi forms)

problem hello i have a c sharp application, which contai ...

更改Html对象Zindex(Change Html Object Zindex)

problem hi all i have an object in my page. i ...

GDI +中发生一般错误的问题。(problem with A generic error occurred in GDI+.)

problem hi all when i want save image from fileupload fa ...

编写非肥皂网服务(Writing Non soap web service)

problem please let me know how to write a non ...

在asp.net和c#中动态创建按钮(Dynamically created button in asp.net and c#)

problem hi, i am creating online examination ...

文件上传问题,找不到文件(File Upload problem, file not found)

problem hi, from my asp.net form, i am trying ...

请在下拉列表中解决错误(please solve error in dropdown list)

problem please solve the error i have 2 dropdownlist. in ...

更改属性上的ReadOnly属性不起作用(Change ReadOnly attribute on property doesn't work)

problem i''ve tried to change a readonly attr ...

我如何分割我的表格(how do i split my form)

problem ok i want to split my form in half so on the left ...

将templatefield动态添加到gridview(adding templatefield dynamically to gridview)

problem give the tutorial to add template field, controls ...

在c#的帮助下导出pdf文件(Export pdf File with the help of c#)

problem how to convert more then one pdf file ...