Mysql 从一个源绑定多表下拉列表

Mysql 从一个源绑定多表下拉列表,mysql,sql,asp.net,vb.net,Mysql,Sql,Asp.net,Vb.net,我有多个下拉列表,我想填写相同的项目 以下代码将仅填充代码中的第一个DropDownList(DropDownList1),而不会填充任何其他代码。为了进行测试,我将“DropDownList3”移到了代码中的第一个位置,以查看会发生什么,然后只将“DropDownList3”填充正确的数据。我需要做什么才能让所有的数据都充满相同的数据 con.Open() cmd1 = New SqlCommand(SqlQuery & SqlQuery2, con) dr1 = cmd1.Execu

我有多个下拉列表,我想填写相同的项目

以下代码将仅填充代码中的第一个DropDownList(DropDownList1),而不会填充任何其他代码。为了进行测试,我将“DropDownList3”移到了代码中的第一个位置,以查看会发生什么,然后只将“DropDownList3”填充正确的数据。我需要做什么才能让所有的数据都充满相同的数据

con.Open()
cmd1 = New SqlCommand(SqlQuery & SqlQuery2, con)
dr1 = cmd1.ExecuteReader

DropDownList1.DataSource = dr1
DropDownList1.DataTextField = "FullInfo"
DropDownList1.DataValueField = "FullInfo"
DropDownList1.DataBind()

DropDownList3.DataSource = dr1
DropDownList3.DataTextField = "FullInfo"
DropDownList3.DataValueField = "FullInfo"
DropDownList3.DataBind()

DropDownList4.DataSource = dr1
DropDownList4.DataTextField = "FullInfo"
DropDownList4.DataValueField = "FullInfo"
DropDownList4.DataBind()

DropDownList5.DataSource = dr1
DropDownList5.DataTextField = "FullInfo"
DropDownList5.DataValueField = "FullInfo"
DropDownList5.DataBind()

DropDownList6.DataSource = dr1
DropDownList6.DataTextField = "FullInfo"
DropDownList6.DataValueField = "FullInfo"
DropDownList6.DataBind()

DropDownList7.DataSource = dr1
DropDownList7.DataTextField = "FullInfo"
DropDownList7.DataValueField = "FullInfo"
DropDownList7.DataBind()
con.Close()
查询需要返回文本和值: 即: query=“从…中选择ID\u字段、名称\u字段”


您可以填写
数据表
,并将其作为源重新使用

Dim dt As DataTable = New DataTable

Dim connection As SqlConnection = New SqlConnection(connStr)
Dim adapter As SqlDataAdapter = New SqlDataAdapter(SqlQuery & SqlQuery2, connection)

adapter.Fill(dt)

DropDownList1.DataSource = dt
DropDownList2.DataSource = dt

谢谢,你的回答把我带到了正确的地方。谢谢您!!
BindDrops(DropDownList1, "NAME_FIELD","ID_FIELD")
BindDrops(DropDownList2, "NAME_FIELD","ID_FIELD")
...
BindDrops(DropDownListN, "NAME_FIELD","ID_FIELD")
Dim dt As DataTable = New DataTable

Dim connection As SqlConnection = New SqlConnection(connStr)
Dim adapter As SqlDataAdapter = New SqlDataAdapter(SqlQuery & SqlQuery2, connection)

adapter.Fill(dt)

DropDownList1.DataSource = dt
DropDownList2.DataSource = dt