Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 27th, 2007, 03:34 PM
Authorized User
 
Join Date: Jul 2007
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Why is multiple record not getting displayed

Hi,
I am using a simple stored procedure from the pubs database to get a resultset. The stored procedure code is as follows:
CREATE PROCEDURE sp_select
@type varchar(40),
@royalty int
AS
select title_id, title, type, royalty
from titles
where
type = @type
AND
royalty = @royalty
GO

Now I am trying to use this stored procedure (passing parameter for type and royalty) as source of recordset. The recordset should display multiple records. The form is unbound. However, through the looping process I am expecting multirow. The form display resultset text boxes are in the detail section. However, I am getting only one record in the resultset in the form when I am expecting multi records. I have no idea why this is happening. Any help is appreciated.
CODE:
Private Sub cmdRunProc2_Click()
'To make all the fields visible

txtTitleID.Visible = True
txtTitle.Visible = True
txtType.Visible = True
txtRoyalty.Visible = True

Dim conn As ADODB.Connection
Dim rs As New ADODB.Recordset
Dim cmdSelect As ADODB.Command
Dim strType As String
Dim curPercent As String

 Set conn = New ADODB.Connection
 Set cmdSelect = New ADODB.Command

 conn.Provider = "SQLOLEDB"

 conn.ConnectionString = "Provider=SQLOLEDB.1;Initial Catalog=pubs;Data Source=USILDEK1-21001;User ID=sa;Password=alloyd;"
 conn.Open

'Code added

cmdSelect.CommandType = adCmdStoredProc
cmdSelect.CommandText = "sp_select"
Set cmdSelect.ActiveConnection = conn

  ' Get the form values
  strType = Forms!frmParamPassing_select!txtBookType
  curPercent = Forms!frmParamPassing_select!txtPercent
  curPercent1 = CCur(Forms!frmParamPassing_select!txtPercent)

    ' Add the parameters
    cmdSelect.Parameters.Append cmdSelect.CreateParameter("@Type", adVarWChar, adParamInput, 12, strType)
    cmdSelect.Parameters.Append cmdSelect.CreateParameter("@Percent", adCurrency, adParamInput, , curPercent1)

   ' Execute the command
 Set rs = cmdSelect.Execute




Do While Not rs.EOF
    txtTitleID = rs.Fields(0)
    txtTitle = rs.Fields(1)
    txtType = rs.Fields(2)
    txtRoyalty = rs.Fields(3)
   rs.MoveNext
Loop

  Set conn = Nothing
  Set cmdSelect = Nothing
  Set rst = Nothing
End Sub

Private Sub Form_Load()
     txtTitleID = ""
     txtTitleID.Visible = False
     txtTitle = ""
     txtTitle.Visible = False
     txtType = ""
     txtType.Visible = False
     txtRoyalty = ""
     txtRoyalty.Visible = False
End Sub
 
Old August 8th, 2007, 02:31 AM
Authorized User
 
Join Date: Sep 2003
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to prabodh_mishra
Default

Hmmm... long que. I presume you need multiple records in txtTitleID etc. but look what are you doing here in loop;
txtTitleID = rs.Fields(0)
With every loop it will refresh the value of text box rather than appending it.
Use this => txtTitleID = txtTitleID & vbcrlf & rs.Fields(0)

Don't forget to make your text box multiline.

Cheers,
Prabodh





Similar Threads
Thread Thread Starter Forum Replies Last Post
handling multiple record sets Phrozt Classic ASP Professional 1 October 12th, 2006 04:33 AM
multiple entries from one record techsp Access 2 August 2nd, 2005 10:10 AM
xslt with multiple occurrences in a record Olaf_l XSLT 2 April 7th, 2005 07:02 AM
Record sharing by multiple users demivolt Access 1 August 26th, 2004 08:17 PM
how to undo the multiple record ??? elleetan Access 6 April 20th, 2004 04:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.