Try
conn.Open
DropDownList1.DataSource = sdr
mydap1.SelectCommand = cmd
mydap1.Fill(ds1, "MachineName")
DropDownList1.DataSource = ds1;
DropDownList1.DataTextField = "MachineName";
DropDownList1.DataValueField = "MachineName";
DropDownList1.DataBind();
.
.
.
conn.Open
DropDownList1.DataSource = sdr
mydap1.SelectCommand = cmd
mydap1.Fill(ds1, "MachineName")
DropDownList1.DataSource = ds1;
DropDownList1.DataTextField = "MachineName";
DropDownList1.DataValueField = "MachineName";
DropDownList1.DataBind();
.
.
.
Dim conn As New SqlClient.SqlConnection
conn.ConnectionString = dsn
Dim cmd As SqlClient.SqlCommand
cmd.Connection = conn
cmd.CommandText = "select MachineName from MachineName_Num"
conn.Open()
DropDownList1.DataSource = cmd.ExecuteReader()
DropDownList1.DataTextField = "MachineName"
DropDownList1.DataValueField = "MachineName"
DropDownList1.DataBind()
conn.Close()
' DropDownList1.DataTextField = mytable1.Rows(i)("MachineName")
' DropDownList1.DataValueField = mytable1.Rows(i)("MachineName")
' DropDownList1.DataBind()
' Next i你这个思路就明显有问题。
DropDownList可以直接绑定DataSet或者DataTable.具体使用方法可以参看楼上两位。其中的DataTextField是DropDownList下拉项的Text值,DataValueField是Value值。
是我的那个 'Dim cmd As SqlClient.SqlCommand
语句中少了一个New
已经解决了