一个早期vb.net写的程序,需要增加功能,要导入excel数据,并按条件显示。
1.数据库端
1.1因为是要把表作为存储过程的输入参数,所以先新建一个数据类型xtabletype
create type xtabletype as table(prodid varchar(20),itemid varchar(20),target varchar(150))
1.2新建存储数据的表
create table import_excel_target
(prodid varchar(200),itemid varchar(20),target varchar(200),id int identity(1,1))
1.3新建存储过程
create procedure import_excel(@tb xtabletype readonly)
as
truncate table import_excel_target
insert into import_excel_target (prodid,itemid,target) select prodid,itemid,target from @tb
2.服务器端
在webservice.axsm文件中添加了一个方法:
<WebMethod()>
Public Function import_excel(dt As DataTable) As String
Dim result As String
Dim parms As New Dictionary(Of String, Object) From {
{"@tb", dt}}
If dt.Rows.Count > 0 Then
dt