www.webdeveloper.com
Results 1 to 7 of 7

Thread: Creating a dataset from multiple tables

  1. #1
    Join Date
    Jun 2004
    Posts
    24

    Creating a dataset from multiple tables

    I am trying to create a dataset using data from multiple tables. however, it does not seem to let me move on to this second table. Here is the code i currently have. Can anyone offer me help as to what direction I should go in to fix my problems?
    Code:
      Sub Page_Load(sender As Object, e As EventArgs)
    
    	dim DtaSetTransfers As Dataset
    	dim accounttransfers As SqlDataAdapter
    
    
    
    	DtaSetTransfers = New DataSet()
    	dim conn as New SQLConnection(connstr) 
    	conn.Open() 
        	accounttransfers = New SqlDataAdapter ("Select AccountName From Accounts",conn) 
    	accounttransfers.Fill (DtaSettransfers, "AccountName")
    	accounttransfers.SelectCommand = New SqlCommand ("Select TerritoryName From Territories",conn)
    	accounttransfers.Fill (DtaSettransfers, "TerritoryName")
    
    	transfers.DataSource = DtaSettransfers
    	transfers.DataBind()
    	conn.Close()
    
    ------------------ Heres my datagride-----------------
    <asp:DataGrid id="transfers" runat="server">
                    <HeaderStyle font-bold="True"></HeaderStyle>
                </asp:DataGrid>

  2. #2
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,222
    grid.datasource=dataset.tables("table").defaultview
    use .tables to distinguish between the two tables for the grid. You can't have a data grid displayingdata from two separate data sets. You can go back and do this all manually though with a loop and response.write out data from two separate places at one time. I prefer to keep my stuff one table per data set so I do not get mixed up though. But just try using .tables when you set a data source.

  3. #3
    Join Date
    Jun 2004
    Location
    Honolulu, Hawaii
    Posts
    13
    You could also try doing a union between the two tables. That way you wouldn't have to worry about doing two tables.

  4. #4
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,222
    Originally posted by roteague
    You could also try doing a union between the two tables. That way you wouldn't have to worry about doing two tables.
    or just using separate data sets too.
    edit: woops, posted something to that extent already... sometimes I forget what I post.

  5. #5
    Join Date
    Jun 2004
    Posts
    4
    try this

    transfers.DataMember= <TableName>
    trnsfer.DataBind()

  6. #6
    Join Date
    Nov 2003
    Posts
    655
    It isn't clear exactly what you're trying to accomplish from your OP. If what you want is a list of accounts with their territories, do a join between the two tables:

    SELECT Accounts.AccountName, Territories.TerritoryName
    FROM Accounts INNER JOIN Territories
    ON Accounts.[Foreign Key from Territories] = Territories.[Primary Key]

  7. #7
    Join Date
    Mar 2008
    Posts
    5

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles