您的位置:程序门 -> vb -> 基础类



如何在vb中用sql访问数据表


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


如何在vb中用sql访问数据表
发表于:2007-07-13 21:06:48 楼主
我自己写了一个,肯定有错误,请帮忙添加修改  
dim   conn   as   new   adodb.connection  
dim   rs   as   new   adodb.recordset  
conn.connectionstring   =   "provider=msdaora.1;password=pppp;user   id=uuuu;data   source=sqlpath;persist   security   info=true " "  
conn.open  
然后下面的查询、插入就写不来了。
只需要有一个简单的查询或插入语句就可以了,就是看一下vb中怎么用sql访问一个user表(字段是username和password)
我写的有错误也请帮忙修正一下
发表于:2007-07-14 15:32:471楼 得分:0
什么数据库,oracle?

检查你的connectionstring!参考如下地址:

http://www.connectionstrings.com/?carrier=oracle

http://www.connectionstrings.com/

发表于:2007-07-14 16:07:562楼 得分:0
dim   strusername   as   string                       '用户名
        dim   struserpwd   as   string                         '用户密码
        dim   l_cnn   as   adodb.connection               '数据库连接对象
        dim   l_strsql   as   string                             '查询sql语句
        dim   l_rs   as   adodb.recordset                   '记录集对象
        set   l_rs   =   new   adodb.recordset
        set   l_cnn   =   new   adodb.connection
        '连接数据库
        l_cnn.connectionstring   =   "provider=msdaora.1;password=pppp;user   id=uuuu;data   source=sqlpath;persist   security   info=true " "   "
        l_cnn.commandtimeout   =   30                       '30内连接数据库。
        l_cnn.open                                                     '连接
       
        l_strsql   =   "select   username,password   from   user   where   username= '你的用户名 ' "
        err.clear
        set   l_rs   =   g_cnnmain.EXECute(l_strsql)
       
        strusername   =   " "
        struserpwd   =   " "
        if   not   (l_rs.eof   and   l_rs.bof)   then                                                   '查询结果没有到文件尾,说明已找到记录
                strusername   =   trim(l_rs.fields( "username ").value)               '取用户帐号
                struserpwd   =   trim(l_rs.fields( "password ").value)                 '取用户密码
        end   if
       
        if   len(trim(strusername))   =   0   then
                msgbox   "未找到 "
        else
                msgbox   "用户名: "   &   strusername   &   "         密码: "   &   struserpwd
        end   if
       
        '释放内存
        if   not   l_rs   is   nothing   then
                if   l_rs.state   =   adstateopen   then   l_rs.close
                set   l_rs   =   nothing
        end   if


快速检索

最新资讯
热门点击