• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • Last Modified:

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
0
hardlearner
Asked:
hardlearner
  • 2
  • 2
1 Solution
 
imperial_p79Commented:
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.
0
 
hardlearnerAuthor Commented:
You are right I have two select statements
0
 
imperial_p79Commented:
if you are using vb.net
First check if dataset.Tables(1) is not nothing and then
dataset.Tables(1).Rows.Count > 0

if both are satisfied then you should be able to get the records from 2nd table as
dataset.Tables(1).Rows(0)("ColumnName")
dataset.Tables(1).Rows(1)("ColumnName")
.
.
.
etc

Hope this helps!
0
 
hardlearnerAuthor Commented:
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

0
 
mani_saiCommented:
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
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now