How to define the desired DataAdapter at runtime

  • Thread starter Thread starter Douglas Buchanan
  • Start date Start date
D

Douglas Buchanan

How do I define the desired DataAdapter at runtime?

A ComboBox is used to select the desired table. The selected value is
the name of the table to be loaded into the datagrid.

My solution works but seems less than elegant.

(Also the Cast to string of the combobox selected value seems awkward.
Any suggestions? - it did not support .ToString() and I could not
firure out why.)

Suggestions please.

====== Code showing my best effort =======

'Get the ValueMember from the cbo
Dim sTableName As String
sTableName = CStr(cboSelectTableOwnerTables.SelectedValue)

Me.dgOwnerTables.DataMember = sTableName

Select Case sTableName
Case "lst1SelectionListMenu"
Me.daSelectionList.Fill(DsLists1,
"lst1SelectionListMenu")
Case "lst2GroupSubListMenu"
Me.daGroupSubList.Fill(DsLists1,
"lst2GroupSubListMenu")
End Select
 
You can do a ByVal?

Sub GetData(ByVal dataadapater1 as SqlDataAdapter, ByVal dsgeneric as
dataset)

Dataddapter1.Clear

'do something with it
'life is good
 
Are you trying to fill a DataTable with a name that corresponds to the
ComboBox value? Am I correct in assuming that regardless of the choice you
are using the exact same select command for the adapter?

You could just use the sTableName in the .Fill statement since in order for
it to hit there, it would have to be that value anyway and that way they'd
always match but it also looks like your using different adapters.

If you could, what's the functionality you're ultimately trying to create?
 
Thank you

scorpion53061 said:
You can do a ByVal?

Sub GetData(ByVal dataadapater1 as SqlDataAdapter, ByVal dsgeneric as
dataset)

Dataddapter1.Clear

'do something with it
'life is good
 
Back
Top