Multiple Tables..?

  • Thread starter Thread starter Kent Johnson
  • Start date Start date
K

Kent Johnson

Hi all,

I have a code that is supposed to load three tables in a dataset.
This works fine with one Dropdownlist1 but not with the other Dropdownlist2.

Tables(0) = "Table0" : Tables(1) = "Table1"
MyDataSet = GetDataSet(strConn, Tables)

For intCount = 0 To Tables.GetUpperBound(0)
objCmd.CommandText = "SELECT * FROM " & Tables(intCount)
objDA.Fill(objDS, Tables(intCount))
Next

DropDownList1.DataSource = MyDataSet
DropDownList1.DataTextField = ("Field1")
DropDownList1.DataValueField = ("Field2")
objDA.Fill(objDS)
DropDownList1.DataBind()

DropDownList2.DataSource = MyDataSet
DropDownList2.DataTextField = ("Field3")
DropDownList2.DataValueField = ("Field4")
objDA.Fill(objDS)
DropDownList1.DataBind()

How can I get the data to Dropdownlist2?

/Kent J.
 
I can give you a couple suggestions:

It looks like you fill your Dataset (ObjDS) in the For Loop in the
beginning, so I'm not sure why you fill it again after assigning your
datasource in both dropdowns. I don't think you need to??

Also, try binding the dropdown lists to the appropriate table in the dataset
(objDS, not MyDataSet?), by using objDS.Tables[0] and objDS.Tables[1] as the
datasource in each.

Other than that I think it looks pretty good.

-Darrin
 
Darrin,
Thanks for your tip with:
objDS.Tables[0] and objDS.Tables[1]

/Kent J.


Darrin J Olson said:
I can give you a couple suggestions:

It looks like you fill your Dataset (ObjDS) in the For Loop in the
beginning, so I'm not sure why you fill it again after assigning your
datasource in both dropdowns. I don't think you need to??

Also, try binding the dropdown lists to the appropriate table in the dataset
(objDS, not MyDataSet?), by using objDS.Tables[0] and objDS.Tables[1] as the
datasource in each.

Other than that I think it looks pretty good.

-Darrin


Kent Johnson said:
Hi all,

I have a code that is supposed to load three tables in a dataset.
This works fine with one Dropdownlist1 but not with the other Dropdownlist2.

Tables(0) = "Table0" : Tables(1) = "Table1"
MyDataSet = GetDataSet(strConn, Tables)

For intCount = 0 To Tables.GetUpperBound(0)
objCmd.CommandText = "SELECT * FROM " & Tables(intCount)
objDA.Fill(objDS, Tables(intCount))
Next

DropDownList1.DataSource = MyDataSet
DropDownList1.DataTextField = ("Field1")
DropDownList1.DataValueField = ("Field2")
objDA.Fill(objDS)
DropDownList1.DataBind()

DropDownList2.DataSource = MyDataSet
DropDownList2.DataTextField = ("Field3")
DropDownList2.DataValueField = ("Field4")
objDA.Fill(objDS)
DropDownList1.DataBind()

How can I get the data to Dropdownlist2?

/Kent J.
 
Back
Top