Try
conn.Open
DropDownList1.DataSource = sdr
mydap1.SelectCommand = cmd
mydap1.Fill(ds1, "MachineName")
DropDownList1.DataSource = ds1;
DropDownList1.DataTextField = "MachineName";
DropDownList1.DataValueField = "MachineName";
DropDownList1.DataBind();
.
.
.

解决方案 »

  1.   

    Dim dsn As String = ConfigurationSettings.AppSettings("DSN_Administer")
            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()
      

  2.   

    For i = 0 To mytable1.Rows.Count - 1
            '        DropDownList1.DataTextField = mytable1.Rows(i)("MachineName")
            '        DropDownList1.DataValueField = mytable1.Rows(i)("MachineName")
            '        DropDownList1.DataBind()
            '    Next i你这个思路就明显有问题。
    DropDownList可以直接绑定DataSet或者DataTable.具体使用方法可以参看楼上两位。其中的DataTextField是DropDownList下拉项的Text值,DataValueField是Value值。
      

  3.   

    不好意思让大家辛苦了
    是我的那个     'Dim cmd As SqlClient.SqlCommand
    语句中少了一个New
    已经解决了