ADO RecordSet RecordCount Property

fpineda101

Well-known member
Joined
Nov 14, 2005
Messages
122
Location
Los Angeles, CA
Programming Experience
1-3
ADO RecordSet RecordCount Property - Resolved

I'm trying this function for a school project. I'm not sure if I am using the correct property. The recordcount property keeps returning as -1 (which probably means False). I test for < 0 in an IF statement and it fails every time. I verified that the data exists, the table name and column name are correct. Can someone provide some insight please?

Below is the code...

Public Function MatchAccountNumber(ByVal value As String) As Boolean
'On Error Resume Next
Dim ConnOracle As ADODB.Connection
Dim Rs1 As ADODB.Recordset
'Dim TCount As Integer
Trim(value)
ConnOracle = New ADODB.Connection
ConnOracle.ConnectionString = "Provider=OraOLEDB.Oracle;Data Source=CIT455;User ID=scott;Password=tiger;"
ConnOracle.Open()
Rs1 = New ADODB.Recordset
SQL = "select account_number from account where account_number = " & value
Rs1 = ConnOracle.Execute(SQL) 'as ADODB.RecordSet;
'TCount = CInt(Rs1.GetRows(Rs1.RecordCount))
If Rs1.RecordCount > 0 Then
MsgBox("Match Found!", MsgBoxStyle.OKOnly, "Account match made")
MatchAccountNumber = True
Else
MsgBox("Match Not Found!", MsgBoxStyle.OKOnly, "Account match not made")
MatchAccountNumber = False
End If
End Function

Thanks in advance for you help!

fpineda101 :eek:
 
Last edited:
Please some one.... push me under a bus.... please.... I can't take it any more. The use of ADO classic in VB.NET is killing me.... so just get it over with. Push me under the next bus. Please.

Using ADO classic in VB.NET is like putting a Ford F-150 engine in a Porche 911.

-tg
ps: just for the record: with a server side cursor, the number of rows returned is unknown. That's why it returns a -1. 3 ways to solve it. 1) jiggle the recordset by doing a .movelast then a .movefirst - .recordcount will be correct then. 2) force a client side cursor - set .CursorLocation on the connection before opening. 3) - and this is my favorite - learn ADO.NET. It can be your friend. There's a couple of tutorials in my signature.
 
Visual Studio: 2003 versus 2005?

Hi Tech Gnome

Thanks for your previous help. I read somewhere that data tables are new to 2005. I am using 2003 for my project. Do your examples in your signature work with VS 2003?

FP :eek:
 
DataTables and DataSets are a part of ADO.NET.... which has been there since .NET 1.0....

The code I used in the tutorials were written using VB 2003 Standard, and so should work just about anywhere.

-tg
 
Instructions for an Oracle DB connection?

Sorry. I forgot to mention that I am using Oracle 9i as my DB. Are there any specific instructions to use with the OleDB class? I can't seem to create the data adapter correctly...
 
Try a google search for OraData ... I think that's what it's called. There is an Oracle specific data adaptor out there (maybr try "oracle data adaptor for .NET") But other than object names, it should be similar. You create the DataAdaptor, create the dataset, fill the data set from the adaptor.... then select from the DataSet.

-tg
 
Back
Top