Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2005
    Posts
    74

    Unanswered: Help with SQL server query..

    Hi can anybody pls. help me...i have these code below to query all data in my 'docs_ref' table where in it has 5 records in it but when i try to execute it and count the record retrieved it always give me a -1 value...what seems to be the problem...any inputs will be greatly appreciated. thanks in advanace!!!

    Code:
        Dim oConn As ADODB.Connection
        Dim rs As ADODB.Recordset
        Set oConn = New ADODB.Connection
        Set rs = New ADODB.Recordset
        oConn.Open "Provider=sqloledb;" & _
                   "Data Source=abs\netsdk;" & _
                   "Initial Catalog=BCMDDB;" & _
                   "User Id=bcmd;" & _
                   "Password=bcmd"
        If oConn.State = adStateOpen Then
            MsgBox "SUCCESSFUL!!!", vbOKOnly
            strSQL = "Select * from docs_ref"
            rs.Open strSQL, oConn
            MsgBox rs.RecordCount, vbOKOnly
            rs.Close
            oConn.Close

  2. #2
    Join Date
    May 2006
    Posts
    16
    Add the following code to your scripts

    oConn.CursorLocation = adUseClient

  3. #3
    Join Date
    Jan 2003
    Location
    Nottinghamshire, UK
    Posts
    364
    Have you tried

    rs.Open strSQL, oConn
    rs.movelast
    MsgBox rs.RecordCount, vbOKOnly

    plus your in the wrong forum for this post

    GW
    "Everything should be made as simple as possible, but not simpler." - Albert Einstein
    "Everything should be made as complex as possible, so I look Cleverer." - Application Developer

  4. #4
    Join Date
    Sep 2005
    Posts
    74
    thanks a bunch!!!!! i got it...but how can i get the value? from recordset? sorry..im just a newbies in SQL...

  5. #5
    Join Date
    May 2006
    Posts
    16
    msgbox rs("FieldName").Value

    You need learn more ADO knowledge from MSDN

  6. #6
    Join Date
    May 2006
    Posts
    1
    or you can try

    Code:
    rs.Open strSQL,oConn,1,1
    
    or
    
    rs.Open strSQL,oConn,3,1
    my first post~hoho
    Last edited by angel1949; 05-29-06 at 02:39.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •