Click here to Skip to main content
14,490,077 members
Rate this:
Please Sign up or sign in to vote.
See more: , +
Actually in my code i am bringing two tables from stored proc and after that i am assigning that two tables to data set
now i want to assign first table to one data table and second table to another data table in my asp.net code. Is it possible.
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

Try this..

DataSet ds = new DataSet();

       DataTable dtTable1 = new DataTable();
       DataTable dtTable2 = new DataTable();


       ds.Tables.Add(dtTable1);
       ds.Tables.Add(dtTable2);


Regards..

Nirav Prabtani

   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

you can access your dataset tables to assign it to anther table like this...


suppose your dataset alias is Ds then you can use something like this...


DataTable dt1 = Ds.Tables[0];
DataTable dt2 = Ds.Tables[1];
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

Yes it is possible
DataSet can contain More then one table
you can create DataTable object and assign DataSet Table to DataTable object
DataTable dt1=DataSetObj.Tables[0];
DataTable dt2=DataSetObj.Tables[1];
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

Public Partial Class WebForm7
    Inherits System.Web.UI.Page
    Public oCn As New System.Data.SqlClient.SqlConnection("Data Source=(local);Initial Catalog=MyDatabase;Uid=sa")

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        fill_data()
    End Sub

    Sub fill_data()
        If oCn.State = ConnectionState.Closed Then
            oCn.Open()
        End If
        Dim dt As New DataTable

        Dim cmd As New SqlClient.SqlCommand("select * from mst_employees", oCn)
        Dim da As New SqlClient.SqlDataAdapter(cmd)
        Dim ds As New DataSet("bpl")
        Dim i As Integer = 0
        dt.Columns.Add(0)
        dt.Columns.Add(1)
        dt.Columns.Add(2)
        dt.Columns.Add(3)
        da.Fill(ds, "bpl")
        If ds.Tables(0).Rows.Count > 0 Then
            While (i <> ds.Tables(0).Rows.Count)
                dt.Rows.Add()
                dt.Rows(i).Item(0) = ds.Tables(0).Rows(i).Item(0).ToString
                dt.Rows(i).Item(1) = ds.Tables(0).Rows(i).Item(1).ToString
                dt.Rows(i).Item(2) = ds.Tables(0).Rows(i).Item(2).ToString
                dt.Rows(i).Item(3) = ds.Tables(0).Rows(i).Item(3).ToString
                i = i + 1
            End While
        End If
        Me.GridView1.DataSource = dt
        Me.GridView1.DataBind()
        oCn.Close()
    End Sub
End Class
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100