Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET 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 April 29th, 2005, 09:06 AM
Authorized User
 
Join Date: Jul 2004
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamic DataAdapter from Typed Dataset



I have a typed DS (xsd) file with numerous tables.

I want to parse through the tables and:

Create a dataadapter for each table
Create the

Something like this...

Sub GetData()
' Open a connection
Dim con As New SqlConnection(CS)
con.Open()

  Dim t As DataTable
    For Each t In MyDs.Tables
    'Create the DataAdapters
     Dim "da" & t.TableName() As New SqlDataAdapter()
     Dim "cb" & t.TableName() As SqlCommandBuilder = New SqlCommandBuilder("da" & t.TableName())

     "da" & t.TableName().SelectCommand = ("select * from " & t.tablename,con)

      "da" & t.TableName().DeleteCommand = "cb" & t.TableName().GetDeleteCommand
      "da" & t.TableName().InsertCommand = "cb" & t.TableName().GetInsertCommand
      "da" & t.TableName().UpdateCommand = "cb" & t.TableName().GetUpdateCommand


"da" & t.TableName().Fill(MyDs, t.TableName())

end sub

Has anyone been able to do something like this???

Thanks!


 
Old May 2nd, 2005, 08:36 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

For generating multiple 'things' like you desire to do, I'd suggest using a HashTable. The SqlDataAdapter will be the object of each HashTable element and the element key can be the name you construct from "da" + t.TableName.

-Peter
 
Old May 3rd, 2005, 06:56 AM
Authorized User
 
Join Date: Jul 2004
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks Peter, but I have no idea what you mean by building a hash table. I'll do some research on it, but if you have an example I'd greatly appreciate it!

Thanks!
David

 
Old May 3rd, 2005, 07:07 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

A hash table is a .NET class that allows you to store a collection of objects. You access the object thru a known key (usually a string). This is compared to a simpler collection such as an array which you can't as easily "find" a particular element in the collection.

Dim hshMyTables As New HashTable

hshMyTables.Item("daTableName") = New SqlDataAdapter

-Peter





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
insert nulls using a typed dataset humour ASP.NET 2.0 Professional 3 April 16th, 2008 05:17 AM
dataadapter --- dataset thas123 ASP.NET 2.0 Basics 0 December 13th, 2006 08:58 AM
Converting a untyped dataset to a typed dataset daphnean Visual Studio 2005 0 July 13th, 2006 01:16 AM
What Are Typed Dataset vinod_pawar1 ADO.NET 2 May 13th, 2005 04:52 AM





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