Link to home
Start Free TrialLog in
Avatar of hardlearner
hardlearner

asked on

Populating data from a dataset onto a webform

Hello there
I have a stored procedure which fetches data from two tables. Coming to the coding part I created a dataset and called the stored procedure to populate all the fields(respective controls) in the webform(data from two tables). I am not able to get the data from the second table(the second table used in stored procedure). I was told to specify as table(0) and table(1) but didnt quite understand. Can anyone help me.

Note: I have declared all the fields in the form equivalent to the respective column names in the database tables
Avatar of imperial_p79
imperial_p79

are there 2 recordset out from your stored procedure? meaning there are 2 select statements in your stored proc and not one select joining 2 tables.
Avatar of hardlearner

ASKER

You are right I have two select statements
ASKER CERTIFIED SOLUTION
Avatar of imperial_p79
imperial_p79

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry but I am a novice. I dont know how to do it.
 Let me explain my problem more clearly.

E.g:

        I have data coming from the first table(table(0)) and filling (xyz,abc...) the respective fields in the form.

xyz.Text = ds.Tables(0).Rows(0).Item("x_y_z")
abc.Text= ds.Tables(0).Rows(0).Item("a_b_c")
-----
-----
-----
Now I have 'qwe.Text' and 'asd.Text' to be filled into  "q_w_e"  and "a_s_d"(a part of  data for the second recordset actually looks into a lookup table)

How do I go about it.

Imperial  I think you answered me but then I wish I had soem experience to grasp it fast.
 Please help me

Hello  hardlearner,

If your stored procedure returns multiple recordsets:

------------------------------------------------------------------------------------------

 Private Sub btnTest_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnTest.Click
        Dim myConnString As String = _
                "User ID=<username>;Password=<strong password>;Initial Catalog=pubs;Data Source=myServer"
        Dim myConnection As New SqlConnection(myConnString)
        Dim myCommand As New SqlCommand()
        Dim myReader As SqlDataReader

        myCommand.CommandType = CommandType.StoredProcedure
        myCommand.Connection = myConnection
        myCommand.CommandText = "MyProc"   'use your stored procedure name here
        Dim RecordCount As Integer

        Try
            myConnection.Open()
            myReader = myCommand.ExecuteReader
            While myReader.Read()
                'Write logic to process data for the first result.
                RecordCount = RecordCount + 1
            End While
            MessageBox.Show("Total number of Authors: " & RecordCount.ToString)

            myReader.NextResult()
            RecordCount = 0

            While myReader.Read()
                'Write logic to process data for the second result.
                RecordCount = RecordCount + 1
            End While
             MessageBox.Show("Authors from California: " & RecordCount.ToString)
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        Finally
            myConnection.Close()
        End Try
    End Sub


-----------------------------------------------------------

Thanks