Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Database Access / September 2004



Tip: Looking for answers? Try searching our database.

Help Getting .RecordCount from Stored Proc

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Toco - 29 Sep 2004 19:59 GMT
Hello.  I am using VB 6 to execute a stored proc, which receives input
parameters.  I created a connection, command, and recordset with ADO.  The
CreatParamater method was used as metadata for type, direction, ect.  .  What
I don't know is if my parameters are not processed correctly, or if I am not
reading the recordset correctly.  My goal is to export the recodset into an
external file, but right now I am testing it by retrieving a recordCount.  
Although I am not receiving an error message, the MsgBox displays a
.RecordCount of -1.  How can this be?  I can execute the SP normally with no
problems.  The input paramters are set to the values of 2 text boxes on the
form.  If any one can shwo me what I am doing wrong, I thank you.  I think my
problem may be how I open my recordset.  Here is code:

Dim cnn1 As ADODB.Connection
Dim cmdProvider As ADODB.Command
Dim prmStartDate As ADODB.Parameter
Dim prmEndDate As ADODB.Parameter
Dim rstProvider As ADODB.Recordset
Dim strCnn As String

Set cnn1 = New ADODB.Connection
strCnn = "Provider=sqloledb;" & _
     "Data Source=MSSQL;Initial Catalog=ClientData;User
Id=pwuser;Password=stlblues; "
cnn1.Open strCnn

Set cmdProvider = New ADODB.Command
Set cmdProvider.ActiveConnection = cnn1

cmdProvider.CommandText = "sp_ProviderLetterError"
cmdProvider.CommandType = adCmdStoredProc

Set prmStartDate = cmdProvider.CreateParameter("@prmStartDate", _
     adDate, adParamInput)
Set prmEndDate = cmdProvider.CreateParameter("@prmEndDate", _
     adDate, adParamInput)
cmdProvider.Parameters.Append prmStartDate
cmdProvider.Parameters.Append prmEndDate

prmStartDate.Value = Me.txtStartDate
prmEndDate.Value = Me.txtEndDate

Set cmdProvider.ActiveConnection = cnn1
Set rstProvider = cmdProvider.Execute

With rstProvider
       MsgBox "OK", vbOKOnly, "There are " & .RecordCount & " records on
this file"
End With
   
rstProvider.Close
cnn1.Close

My recordset always comes out as -1...why is this?  I have tested query
normally and there is data.  Perhaps another issue is my cursortype.

Toco
Al Reid - 29 Sep 2004 20:00 GMT
> Hello.  I am using VB 6 to execute a stored proc, which receives input
> parameters.  I created a connection, command, and recordset with ADO.  The
[quoted text clipped - 52 lines]
>
> Toco

Both CursorType and CursorLocation are involved.  If you use a CursorLocation of adUseClient, your RecordCount should be accurate.
John Wright - 29 Sep 2004 20:29 GMT
When you open the recordset do so in the following
With rstProvider
       .CursorLocation = adUseClient
       .CursorType = adOpenStatic
       .LockType = adLockReadOnly
       .Open cmdProvider
End With
If you set the recordset to the execute method of the command you get a
firehose cursor in return regardless of how you set up your recordset.  As a
result you will get -1 from a recordcount.

John

> Hello.  I am using VB 6 to execute a stored proc, which receives input
> parameters.  I created a connection, command, and recordset with ADO.  The
[quoted text clipped - 52 lines]
>
> Toco
Val Mazur - 30 Sep 2004 04:12 GMT
Hi,

Check next KB about it

http://support.microsoft.com/default.aspx?scid=kb;en-us;194973

Signature

Val Mazur
Microsoft MVP

> Hello.  I am using VB 6 to execute a stored proc, which receives input
> parameters.  I created a connection, command, and recordset with ADO.  The
[quoted text clipped - 58 lines]
>
> Toco
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.