Click to See Complete Forum and Search --> : Creating a dataset from multiple tables


cusoxty
06-21-2004, 10:23 AM
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?

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>

PeOfEo
06-21-2004, 01:10 PM
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.

roteague
06-21-2004, 09:23 PM
You could also try doing a union between the two tables. That way you wouldn't have to worry about doing two tables.

PeOfEo
06-21-2004, 11:43 PM
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.

ravisankar
06-23-2004, 04:18 AM
try this

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

CardboardHammer
06-30-2004, 10:54 AM
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]

robertsams23
10-23-2008, 01:14 AM
try these links

http://vb.net-informations.com/dataset/vb.net-ado.net-dataset-tutorial.htm

http://vb.net-informations.com/dataset/dataset-multiple-tables-sqlserver.htm

lemo