您的位置:程序门 -> vb -> 数据库(包含打印,安装,报表)



将excel数据导入到vb的问题


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


将excel数据导入到vb的问题
发表于:2007-05-21 11:31:57 楼主
从excel导入数据到mshflexgrid,为什么只显示了第一条记录
代码如下:
on   error   goto   errorhandler
dim   xlsconn   as   new   adodb.connection
dim   xlscmd   as   new   adodb.command
dim   rs   as   new   adodb.recordset
        commondialog1.showopen
        xlsconn.connectionstring   =   "provider=microsoft.jet.oledb.4.0;data   source= "   &   commondialog1.filename   &   ";extended   properties=excel   8.0;persist   security   info=false "

        xlsconn.open
       
        if   msgbox( "确实要导入数据吗? ",   vbinformation   +   vbyesno,   me.caption)   =   vbyes   then
                rs.open   "select   *   from   [sheet1$]   ",   xlsconn
                set   mshflexgrid1.datasource   =   rs

                if   rs.eof   and   rs.bof   then
                        msgbox   "导入失败 ",   vbinformation,   me.caption
                else
                        msgbox   "记录已被导入 ",   vbinformation,   me.caption
                end   if
        end   if
        set   xlsconn   =   nothing
        set   rs   =   nothing
exit   sub
errorhandler:
        msgbox   err.description,   vbinformation,   me.caption

发表于:2007-05-21 12:22:431楼 得分:0
题目就借了,应该是在vb中打开excel才对啊!
发表于:2007-05-21 12:51:362楼 得分:0
……   先别管题目了,帮忙解决下问题吧
发表于:2007-05-21 15:57:333楼 得分:0
關注!
发表于:2007-05-21 16:39:074楼 得分:0
没用过mshflexgrid,也不用绑定。帮不上忙了。
不过你可以用

do   while   not   rs.eof
        debug.print   rs.fields(0)
        rs.movenext
loop
rs.close
来试看看打开是否成功!
发表于:2007-07-12 11:41:465楼 得分:0
说出邮箱,发给你现成的函数
发表于:2007-07-18 10:16:536楼 得分:0
我也有同样的问题“如何将excel数据直接导入到vb的问题   ”,请多多指教!谢谢!
我的邮箱是cxgnj@163.com
发表于:2007-07-18 15:20:377楼 得分:0
你可以用mshflexgrid1.textmatrix(   ,   )=rs.fields(   )


快速检索

最新资讯
热门点击