您的位置:程序门 -> .net技术 -> c#



将excel导入到sql中遇到的问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


将excel导入到sql中遇到的问题
发表于:2007-03-08 09:38:25 楼主
语句如下:                
string   strpath   =   this.server.mappath( ". ")   +   "\\test1.xsl ";
                string   sconnectionstring   =   "provider=microsoft.jet.oledb.4.0;data   source= "+   strpath   + ";extended   properties=excel   8.0; ";
                oledbconnection   con   =   new   oledbconnection(sconnectionstring);
                con.open();
在打开连接时抱错

有人说可以用存储过程
select     *     from     opendatasource( 'microsoft.jet.oledb.4.0 ', 'data     source=d:\test1.xls;extended       properties=excel       5.0;persist       security       info=false ')...[sheet1$]
也不行,ole   db   提供程序   'microsoft.jet.oledb.4.0 '   报错。  
[ole/db     provider   returned   message:   找不到可安装的   isam。]  

该怎么解决啊?(我在对应目录各放了一个test1.xsl)
发表于:2007-03-08 09:46:261楼 得分:0
自己顶一下~
哪位大哥有上传excel文件并将它导入到sql数据库的代码么?贴一下啊~
多谢啦~
发表于:2007-03-08 10:12:512楼 得分:0
dataset   mydataset;
                        string   strcon   =   "   provider   =   microsoft.jet.oledb.4.0   ;   data   source   =   "   +   filename   +   ";extended   properties=excel   8.0 ";
                        oledbconnection   myconn   =   new   oledbconnection(strcon);
                        string   strcom   =   "   select   *   from   [sheet1$]   ";
                        myconn.open();
                        oledbdataadapter   mycommand   =   new   oledbdataadapter(strcom,   myconn);
                        mydataset   =   new   dataset();
                        mycommand.fill(mydataset,   "[sheet1$] ");
                        myconn.close();
                        if   (mydataset.tables[0].columns.count   !=   4)
                        {
                                //列数不正确
                                return   null;
                        }
发表于:2007-03-08 10:13:293楼 得分:0
你有没有安装odbc啊。
发表于:2007-03-08 10:39:494楼 得分:0
安装了
发表于:2007-03-08 10:41:135楼 得分:0
select   *  
from   opendatasource(   'microsoft.jet.oledb.4.0 ',
    'data   source= "d:\test1.xls ";user   id=admin;password=;extended   properties=excel   5.0 ')...[sheet1$]
在查询分析器里可以执行
发表于:2007-03-08 11:06:416楼 得分:0
顶啊~


快速检索

最新资讯
热门点击