dim cnn as new adodb.connection
dim af as long
cnn.open conStr
cnn.execute "select * from xtable",af,adCmdTextxtable中有数据,可是af的值还是-1
af的值不是运行语句后影响的行数吗?不解,郁闷,帮忙看看,谢谢!!

解决方案 »

  1.   

    cnn.CursorLocation = adUseClient
      

  2.   

    dim cnn as new adodb.connection
    dim af as long
    cnn.CursorLocation = adUseClient '<---------------------设置客户端游标
    cnn.open conStr
    cnn.execute "select * from xtable",af,adCmdText
      

  3.   

    用客户端游标
    cnn.CursorLocation = adUseClientadUseClient 使用由本地游标库提供的客户端游标。本地游标引擎通常允许使用的许多功能可能是驱动程序提供的游标无法使用的,因此使用该设置对于那些将要启用的功能是有好处的。adUseClientBatch 与 adUseClient 同义,也支持向后兼容性。 
    adUseServer 默认值。使用数据提供者或驱动程序提供的游标。这些游标有时非常灵活,对于其他用户对数据源所作的更改具有额外的敏感性。但是,Microsoft Client Cursor Provider(如已断开关联的记录集)的某些功能无法由服务器端游标模拟,通过该设置将无法使用这些功能。
      

  4.   

    dim cnn as new adodb.connection
    Private Sub Command1_Click()
        Dim af As Long
        af = 0
        cnn.CursorLocation = adUseClient
        cnn.Open "Provider=SQLOLEDB.1;Password=;Persist Security Info=True; "_
                  & "User ID=sa;Initial Catalog=Bingo;Data Source=cosmos\mydb"
        cnn.Execute "select * from wwUser", af, adCmdText
        Text1.Text = af
    End Sub这样做还是得不到,af的值还是不对啊
      

  5.   

    dim cnn as new adodb.connection
    dim rst as new adodb.recordset'<------------------------------定义记录集对象
    Private Sub Command1_Click()
        Dim af As Long
        af = 0
        cnn.CursorLocation = adUseClient
        cnn.Open "Provider=SQLOLEDB.1;Password=;Persist Security Info=True; "_
                  & "User ID=sa;Initial Catalog=Bingo;Data Source=cosmos\mydb"
        set rst=cnn.Execute("select * from wwUser", af, adCmdText)'<------------给rst赋值
        Text1.Text = af'得到影响的行数
    End Sub
      

  6.   

    楼上的各位兄弟,你们的方法我都试了,还是-1啊(ADO2.8)
      

  7.   

    '模块中
    Public CurConn As New ADODB.Connection      '数据库连接
    Sub Main()
    '连接字符串(本例子是oracle,对别的一样)
    strConn = "Provider=OraOLEDB.Oracle.1;Persist Security Info=True;" & _
            "Data Source=" & strDataSource & ";" & _
            "User ID=" & LogID & ";" & _
            "Password=" & LogPWD
        
        With CurConn
            .CommandTimeout = 3
            .ConnectionTimeout = 3
            .ConnectionString = strConn
            .Open
            .CursorLocation = adUseClient
        End With
        frm_main.Show
        Exit Sub    
    errConn:
        MsgBox Err.Description, vbCritical + vbOKOnly, "错误"
    end Sub
    '读记录*******************************
    Private Sub CmdQuery_Click()
        Dim sQuery As String
        Dim QueryRS As New ADODB.Recordset
        sQuery = "select * from 表名"
        On Error GoTo ErrQuery
        Set QueryRS = CurConn.Execute(sQuery)
        If Not (QueryRS.BOF And QueryRS.EOF) Then
            Do While Not QueryRS.EOF
                '此处往表格里写
                QueryRS.MoveNext
            Loop
        Else
            MsgBox "没有记录!", vbExclamation, "提示信息"
        End If
        QueryRS.Close
        Set QueryRS = Nothing
        Exit Sub
    ErrQuery:
        MsgBox Err.Description, vbCritical, "提示信息"
    End Sub
      

  8.   

    如果想得到记录数 建议用select count()去查
    ado的记录集里记录的数量本来就是个近似值 
    你可以看看msdn里面写的很清楚