Results 1 to 2 of 2

Thread: Results from Stored Procedure to textboxes

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    Results from Stored Procedure to textboxes

    I have a stored procedure that returns results like this:

    Store#, Qty, and Item (see example below).

    1, 3, Fountain Drinks
    1, 2, CandyBars
    1, 5, Hard Candies

    I am trying to take those results and put them into text boxes on my form but so far all I have been able to do is get the last record to show on my form. What I need to do is to put the QTY of Fountain Drinks in the tbStoreFF textbox and ten QTY of CandyBars in the tbStoreCB textbox. How can I accomplish that? The code below is what I have managed thus far.

    vb Code:
    1. Private Sub ExecuteCountServices(ByVal parStore As String, _
    2.         ByVal parStart As DateTime, ByVal parEnd As DateTime)
    3.  
    4.         Dim strSp As String = "sp_CountServicesStore"
    5.         Dim cn As SqlConnection = New SqlConnection
    6.         Dim cmd As SqlCommand = New SqlCommand(strSp, cn)
    7.         Dim dr As SqlDataReader
    8.  
    9.         cn.ConnectionString = Con
    10.         cn.Open()
    11.  
    12.         cmd.CommandType = CommandType.StoredProcedure
    13.         cmd.Parameters.Add("@Store", SqlDbType.VarChar).Value = parStore
    14.         cmd.Parameters.Add("@StartDate", SqlDbType.DateTime).Value = parStart
    15.         cmd.Parameters.Add("@EndDate", SqlDbType.DateTime).Value = parEnd
    16.         tbMyStore.Text = parStore
    17.         tbMyStart.Text = CStr(parStart)
    18.         tbMyEnd.Text = CStr(parEnd)
    19.  
    20.         Try
    21.             dr = cmd.ExecuteReader()
    22.             While dr.Read()
    23.                 With dr
    24.                     tbStoreFF.Text = CStr(.Item("QTY"))
    25.                     ' textbox for Fountain Drinks here
    26.                     ' textbox for candy bars
    27.                     ' textbox for hard candies
    28.                 End With
    29.             End While
    30.         Catch ex As Exception
    31.             MessageBox.Show(ex.Message & vbNewLine & _
    32.             ex.Source, "Data Error", MessageBoxButtons.OK)
    33.         End Try
    34.     End Sub
    Last edited by FastEddie; Aug 17th, 2007 at 12:31 PM.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Results from Stored Procedure to textboxes

    Moved to database development

Posting Permissions

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



Click Here to Expand Forum to Full Width