?
Solved

Populating data from a dataset onto a webform

Posted on 2005-03-24
5
Medium Priority
?
258 Views
Last Modified: 2010-04-23
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
Comment
Question by:hardlearner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:imperial_p79
ID: 13622044
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
 

Author Comment

by:hardlearner
ID: 13622060
You are right I have two select statements
0
 
LVL 4

Accepted Solution

by:
imperial_p79 earned 150 total points
ID: 13622082
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
 

Author Comment

by:hardlearner
ID: 13622479
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
 
LVL 8

Expert Comment

by:mani_sai
ID: 13622732
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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question