Click here to Skip to main content
15,894,539 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am waiting to create dataadapters by using table names.

here is what I have so far

Dim IDlibrary As DataSet = New DataSet("all_tables")
IDlibrary.Tables.Add("Profile")

'fill datatables in dataset
        For Each tab As DataTable In IDlibrary.Tables
            alltabadaptors.SelectCommand = New SqlCommand("select * from " + tab.TableName, sqlconn1)
            alltabadaptors.SelectCommand.ExecuteNonQuery()
            alltabadaptors.Fill(IDlibrary, tab.TableName)
        Next


this works extremely well when filling all datatables. However, because there has to be a seperate table adapter per table. How can I call by string a dataadapter?

so instead of this
alltabadaptors.SelectCommand = New SqlCommand("select * from " + tab.TableName, sqlconn1)
is there a way to call a manually made dataadapter

("stringname for dataadapter here").SelectCommand = New SqlCommand("select * from " + tab.TableName, sqlconn1)


What I have tried:

I have tried to do research on call a dataadapter by string name but I could not find much.
Posted
Updated 8-Jun-20 19:58pm
Comments
Dave Kreskowiak 8-Jun-20 23:37pm    
First question, why are you using TableAdapters?

Next, why are you loading every table in your database into a DataSet?
Member 11856456 9-Jun-20 19:15pm    
if there is something better than table adapters I would like to know about it that way I can expand my knowledge. Also, I am loading them all so I can find an update the row found in my match statement. I am doing what I can to increase the speed of my match statement code. I appreciate any help.

1 solution

YOu can't.
But ... You could store the DataAdapters in a Dictionary and access them that way:
VB
Dim adapters As Dictionary(Of String, SqlDataAdapter) = New Dictionary(Of String, SqlDataAdapter)()
adapters.Add("Customers", New SqlDataAdapter())
adapters.Add("Invoices", New SqlDataAdapter())
...
Dim tableName As String = "Invoices"
adapters(tableName).SelectCommand = New SqlCommand("SELECT * FROM " & tableName, con)
 
Share this answer
 
Comments
Member 11856456 9-Jun-20 19:16pm    
Griff, been awhile. Thank you for the response, this is a very interesting way to achieve what i am looking for. I really appreciate the help as i was stuck.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900