想把excel导入数据,winform做一个小工具,选择excel文件,怎么把这个文件路径和名字做过程参数存储过程winform,.net 存储过程winform

解决方案 »

  1.   

    直接在存储过程中用 VARCHAR类型就可以了吧 。
      

  2.   

    以VB为例,选择文件用CommonDialog控件,
    文件路径: CommonDialog.filename属性
    文件名: CommonDialog.FileTitle属性
      

  3.   

    create pro daoru
    as
    insert into tb_yuanbiao select *from
    openrowset('microsoft.jet.oledb.4.0','excel 5.0;hdr=yes;database=e:原文件.xls‘,sheet1&)
    怎么修改啊
      

  4.   

    用BCP命令,可以放很多参数进去。
      

  5.   

    create proc daoru
    @path nvarchar(1000)
    as
    begin declare @sql nvarchar(max)
    select @sql=
    'insert into tb_yuanbiao select *from
    openrowset(''microsoft.jet.oledb.4.0'',''excel 5.0;hdr=yes;database='+@path+''',sheet1&)' exec(@sql)
    end
      

  6.   

    我使用了这个,想把文件路径和文件名都做成参数可以吗?DATEBASE=@path,sheet1$提示不包含表"sheet1$
      

  7.   

    指定的EXCEL文件中有sheet1嗎?
      

  8.   

    try this,create proc daoru
    (@filepath varchar(100),  --> 文件路径
     @filename varchar(100)   --> 文件名
    )
    as
    begin
     declare @tsql varchar(6000)
     
     select @tsql='insert into tb_yuanbiao select * from '
                 +' openrowset(''microsoft.jet.oledb.4.0'',''excel 5.0;hdr=yes;database='+@filepath+'\'+@filename+';'' '
                 +' ,''select * from [sheet1$]'') '
                 
     exec(@tsql)             
    end
      

  9.   

    +号语法错误,能不能文件路径和文件名用弄一个参数,我是想用winform直接选取文件执行存储过程
      

  10.   

    试试这个,调用例子: exec daoru @filepath='D:\ap',@filename='001.xlsx'
    PS:若仍有问题,将存储过程中的exec(@tsql)改为print @tsql,打印出来看看.create proc daoru
    (@filepath varchar(100),  --> 文件路径
     @filename varchar(100)   --> 文件名
    )
    as
    begin
     declare @tsql varchar(6000)
      
     select @tsql='insert into tb_yuanbiao select * from '
                 +' openrowset(''microsoft.jet.oledb.4.0'',''excel 5.0;hdr=yes;database='+@filepath+'\'+@filename+';'', '
                 +' ''select * from [sheet1$]'') '
                  
     exec(@tsql)             
    end
      

  11.   

    可以了,谢谢,我需要部分字段查询在导出到新的excel,用bcp?能帮忙写一下吗,万分感谢
      

  12.   

    bcp导出.
    参考 http://www.cnblogs.com/xiaogangqq123/archive/2011/09/30/2196727.html