Multiple Tables..?

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.
 
D

Darrin J Olson

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
 
K

Kent Johnson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top