关于ADO的问题   dim a as new adodb.connection
   dim a as new adodb.command
   dim a as new adodb.parameter
   dim a as new adodb.stream
   dim a as new adodb.recordset
   dim a as new adodb.record
   其中a的用法,和a用途,要很经典的!!例如,要说出command最主要用来做什么,
        dim a as new adodb.connection
        dim c as string
        c="select....."
        a.execute c
可以写成这样吗??
        dim a as new adodb.connection
        dim b as new adodb.command
        dim c as string
        c="select....."
        Set b.ActiveConnection = a
        haha.CommandText = c
        haha.Execute 
        
                   我是菜鸟!!

解决方案 »

  1.   

    可以写成这样
    dim a as new adodb.connection
            dim c as string
            c="select....."
       
            a.execute c
    主要是执行 sql 语句
      

  2.   

    dim a as new adodb.connection
            dim b as new adodb.command
            dim c as string
            c="select....."
            b.ActiveConnection = a
            b.CommandType = adCmdText
            b.CommandText = c
            b.Execute 
      

  3.   

    Dim adoCmm As New ADODB.Command
     Dim Rs As New ADODB.Recordset
     Dim adoRec As New ADODB.Recordset
     adoCnn.CursorLocation = adUseClient
     adoCnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB;Persist Security Info=False" adoCmm.ActiveConnection = adoCnn
     adoCmm.CommandType = adCmdText
     adoCmm.CommandText = "select * from employees"
     Set adoRec = adoCmm.Execute
     
     Set DataGrid1.DataSource = adoRec
    command对象
    command对象的主要目的是执行参数化的存储过程。其形式要么是临时准备(prepared),要么是持久的预编译(precompiled)过的sql语句。如果想(存储)一个或多个查询以供在同一connection上多次执行,command对象也是很有用的。当想创建recordset时,一种高效的方法是绕过command对象而采用recordset.open方法。 
    属性
    属性名称 数据类型和用途 
    activeconnection 指针类型,指向command所关联的connection对象。对于现存的已打开连接,可使用set cmmname.activeconnection=cnnname。另外,也可以不用相关connection对象名称而使用有效的连接字符串去创建一个新的连接。默认值为null。  
    commandtext 可读写string类型。为activeconnection指定一条sql语句、表名、存储过程名或提供者能接受的任意字符串。commandtype属性的值决定了commandtext属性值的格式。默认值为空字符串:"" 
    commandtimeout 可读写long类型,指定中止一个command.execute调用之前必须等待的时间。这时的值优先于connection.comandtimeout中的设定值。默认值为30秒。 
    commandtype 可读写long类型,指定数据提供者该如何解释commandtext属性值。commandtype等效于connection.execute方法中的可选参数lngoption。详见commandtype所用到的常数。默认值为adcmdunkown. 
    name 可读写string类型,指定command的名称。 
    prepared 可读写boolean类型,判断数据源是否把commandtext中的sql语句编译为prepared statement(一种临时性存储过程)。prepared statement仅存活于command的activeconnection生命周期中。许多客户/服务器rdbms,包括sql server,都支持prepared statement。如果数据源不支持prepared statement,则把该属性设为true,将导致一个自陷错误。 
    state 可读写long类型,指定commnad状态。见state常数。 
    注意:最好每次都为commandtype指定的一个合适的常数值,否则会降低系统运行的效率。
    方法
    方法 用途 
    createparameter 在执行该方法之前,必须首先声明一个adodb.parameter对象。调用语法为:
    cmmname.createparameter [strname[,lngtype[,lngdirection[,lngsize[,varvalue]]]]] 
    execute 调用语法同connection.execute大致相同。 
    常数
    state常数
    常数 含义 
    adstateclosed connection(或其他对象)是关闭的(默认值) 
    adstateconnecting 正在连接数据源的状态 
    adstateexecuting connection或command对象的execute方法已被调用 
    adstatefetching 返回行(row)到recordset对象 
    adstateopen connection(或其他对象)是打开的(活动的) 
    commandtype所用到的常数
    command类型常数 含义 
    adcmdunknown command类型未定(默认值),由数据提供者去判别command语法 
    adcmdfile command是和对象类型相应的文件名称 
    adcmdstoredproc command是存储过程名称 
    adcmdtable command是能产生内部select * from tablename查询的表名称 
    adcmdtabledirect command是能直接从表中获取行内容的表名称 
    adcmdtext command是一条sql语句 
      

  4.   


    看这个:ADO三大对象的属性、方法、事件及常数http://www.csdn.net/Develop/list_article.asp?author=joo