Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 12th, 2007, 08:29 PM
Registered User
 
Join Date: Jul 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to create an extra table in a dataset??

I am pulling records from 3 tables using "Select * From Tablename" (just for quick and dirty functionality).

But I need to join two of the tables to make a fourth table that does not exist in the source database. How do I create this fourth table inside the existing dataset??
 
Old July 13th, 2007, 10:57 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Dim myConnection As SqlConnection
Dim myDataAdapter As SqlDataAdapter
Dim myDataSet As DataSet
Dim myDataTable As DataTable
Dim Publisher As DataRow
Dim Title As DataRow

myConnection = New SqlConnection( "server=localhost;uid=sa;pwd=secret;database=P ubs" )
myDataSet = New DataSet()
myDataAdapter = New SQLDataAdapter( "Select * From Publishers", myConnection )
myDataAdapter.Fill( myDataSet, "Publishers" )
myDataAdapter.SelectCommand = New SqlCommand( "Select * From Titles", myConnection )
myDataAdapter.Fill( myDataSet, "Titles" )

myDataSet.Relations.Add( "PubTitles", myDataSet.Tables( "Publishers" ).Columns( "pub_id" ), myDataSet.Tables( "Titles" ).Columns( "pub_id" ) )

For Each Publisher in myDataSet.Tables( "Publishers" ).Rows
  Response.Write( "<p>" & Publisher( "pub_name" ) & ":" )
  For Each Title In Publisher.GetChildRows( "PubTitles" )
    Response.Write("<li>" & Title( "title" ) )
  Next
Next

 
Old July 13th, 2007, 10:29 PM
Registered User
 
Join Date: Jul 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by rstelma
 Dim myConnection As SqlConnection
Dim myDataAdapter As SqlDataAdapter
Dim myDataSet As DataSet
Dim myDataTable As DataTable
Dim Publisher As DataRow
Dim Title As DataRow

myConnection = New SqlConnection( "server=localhost;uid=sa;pwd=secret;database=P ubs" )
myDataSet = New DataSet()
myDataAdapter = New SQLDataAdapter( "Select * From Publishers", myConnection )
myDataAdapter.Fill( myDataSet, "Publishers" )
myDataAdapter.SelectCommand = New SqlCommand( "Select * From Titles", myConnection )
myDataAdapter.Fill( myDataSet, "Titles" )

myDataSet.Relations.Add( "PubTitles", myDataSet.Tables( "Publishers" ).Columns( "pub_id" ), myDataSet.Tables( "Titles" ).Columns( "pub_id" ) )

For Each Publisher in myDataSet.Tables( "Publishers" ).Rows
Response.Write( "<p>" & Publisher( "pub_name" ) & ":" )
For Each Title In Publisher.GetChildRows( "PubTitles" )
    Response.Write("<li>" & Title( "title" ) )
Next
Next

THANK YOU! That helps a lot!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Create new row using a typed dataset humour ASP.NET 2.0 Professional 0 May 9th, 2008 09:49 PM
Create generic XSL Template to create table Venkatachalapathy XSLT 5 March 11th, 2008 07:49 AM
Create a DataSet in a Web Service amirdiwan C# 2005 1 February 22nd, 2007 04:52 PM
create a relation betwn 2 tables in a dataset dhol General .NET 1 August 9th, 2005 09:17 AM
Create new dataset from two existing datasets wmoy C# 3 June 28th, 2005 09:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.