Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi All,

 

I've been having this problem for over a day now, and I can't pinpoint where the problem lies. Here is the code:

 

Private Function WatchWord(ByVal sTranscript As String) As String

Dim sWord, sUWord As String

Dim sFind As String

Dim ifind, iIndex, iPrior As Integer

'

Dim rscase As ADODB.Recordset

Dim connxn As ADODB.Connection

Dim ConnxnStr As String

ConnxnStr = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=EDMS"

'

sExec = "Select word from Words"

'

Set connxn = New ADODB.Connection

connxn.Open ConnxnStr

Set rscase = New ADODB.Recordset

rscase.Open sExec, connxn

MsgBox (CStr(rscase.RecordCount)) 'I get a -1

'

While Not rscase.EOF 'For iIndex = 0 To rscase.RecordCount - 1

sWord = rscase.Fields(0).Value

sTranscript = UCase(sTranscript)

sUWord = LTrim(RTrim(UCase(sWord)))

ifind = InStr(1, sTranscript, sUWord, vbTextCompare)

If ifind > 0 Then

iPrior = iPrior + 1

If sFind = "" Then

sFind = LTrim(RTrim(sWord))

Else

sFind = sFind + ", " + LTrim(RTrim(sWord))

End If

End If

rscase.MoveNext

'Next

Loop

'

rscase.Close

connxn.Close

Set rscase = Nothing

Set connxn = Nothing

'

If iPrior >= 2 Then

sPriority = "High"

ElseIf iPrior = 1 Then

sPriority = "Medium"

Else

sPriority = "Low"

End If

'

WatchWord = sFind

End Function

 

I've used almost the exact same code in several other functions that have the recordset insert, update and retrieve, and they all work fine. This one decides it doesn't want to work. That messagebox that gets the rowcount returns a -1, and there are 16 rows in the table. What could be wrong?

 

Thanks in advance!

 

:confused:

  • *Experts*
Posted

This is ADO code, not ADO.NET. First, you're in the wrong forums.

 

Second (answer), in ADO you can't guarantee the RecordCount will be accurate until you've gone to the end of the RecordSet by using MoveNext to the end, or MoveLast. You may be able to read the RecordCount in some cases (it sounds like it works sometimes), but definitely DO NOT count on that. You should use the .EOF property like you are - it's safer.

 

If you really need the record count, you'll have to first check BOF or EOF, then loop through using MoveNext til the end, then check the RecordCount. Don't forget to go back to the beginning before trying to use your Recordset.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...