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



大菜鸟请教vb+access


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


大菜鸟请教vb+access
发表于:2007-05-29 17:14:37 楼主
我想从access数据库中查询一个值(单位名称),在vb工程的text5中显示出来,不用datagrid控件或者datalist控件显示.
这个值存放在表1中,我所做的工程用ado控件与表2进行连接成功,请问各位大侠们这个程序如何编写....................
分数不够,只能给20分了,不好意思,请见谅!
if   text1.text   <>   " "   then
      if   text2.text   <>   " "   then
      dim   databaseconnection   as   new   connection
      dim   cmd   as   new   command
                databaseconnection.connectionstring   =   "provider=microsoft.jet.oledb.4.0;data   source=adodc1.mdb;persist   security   info=false "
                databaseconnection.open
                set   cmd.activeconnection   =   databaseconnection
                cmd.commandtext     = "select   单位名称   from   表1,   表2   where   表1.年份=表2.年份   and   表1.月份=表2.月份 "
                cmd.commandtype   =   adcmdtext
                cmd.EXECute
                text5.text   =   cmd.EXECute.fields(0)
      end   if
end   if
text1和text2分别为年份和月份.
这个是我请教别人回帖,我综合了一下,程序运行后成死状态.........
请各位大侠帮帮我,不然毕业设计过不了,要不帮我重新写个可以实现这个功能的也行,谢谢.................
万分感激................
发表于:2007-05-29 19:29:331楼 得分:0

                text5.text   =   cmd.EXECute.fields(0)
你看看msdb中关于ado的操作好吗?这句是错的。
发表于:2007-05-30 09:38:272楼 得分:0
请教该如何编写,我刚学.......
按照上面的程序运行后系统出现实时错误,找不到文件 'g:\adodc1.mdb '
谢谢了.............
发表于:2007-05-30 09:48:013楼 得分:0
if   text1.text   <>   " "   and   text2.text   <>   " "   then

      dim   rs   as   new   adodb.recordset

      set   rs   =   adodc1.recordset.activeconnection.EXECute( "select   单位名称   from   表1   where   年份= ' "   &   text1   &   " '   and   月份= ' "   &   text2   &   " ' ")

      if   not   rs.eof   then   text5.text   =   rs!单位名称

      set   rs   =   nothing

end   if
发表于:2007-05-30 09:58:204楼 得分:0
楼上的高手,系统运行后显示至少有一个参数没有被指定值
发表于:2007-05-30 10:35:265楼 得分:0
请各位帮帮忙,实在是不会.................
发表于:2007-05-31 10:22:086楼 得分:0
做个几天,到现在还是不会.................
郁闷了...............
请高手帮帮忙................
发表于:2007-06-01 16:56:207楼 得分:0
dim   re   as   new   adodb.recordset
dim   cn   as   new   adodb.connection
dim   sql   as   string
cn_str   =   "provider=microsoft.jet.oledb.4.0;data   source=adodc1.mdb;persist   security   info=false "
com.activeconnection   =   cn_str
cn.open   cn_str

sql== "select   单位名称   from   表1,   表2   where   表1.年份=表2.年份   and   表1.月份=表2.月份 "
re.open   sql_select,   cn,   adopendynamic,   adlockoptimistic

if   not   (re.bof   and   re.eof)   then
text5.text   =   re( "单位名称 ")
end   if

set   cn   =   nothing
set   re   =   nothing

记得给我分.
发表于:2007-06-01 16:57:018楼 得分:0
sql= "select   单位名称   from   表1,   表2   where   表1.年份=表2.年份   and   表1.月份=表2.月份 "
这个多个=
发表于:2007-06-01 17:00:159楼 得分:0
cn_str   =   "provider=microsoft.jet.oledb.4.0;data   source=c:\hotelmanager\database\data.mdb;persist   security   info=false "

原则ado   是用odbc   的   你这么写也行

cn_str   =   "provider=msdasql.1;persist   security   info=false;data   source=data;   pwd= "

data   是odbc中的建立的数据源
发表于:2007-06-02 10:00:3810楼 得分:0
好的,我试试看.
发表于:2007-06-04 15:07:2211楼 得分:0
不行。。。。。。。
出错,要求对象。


快速检索

最新资讯
热门点击