改为
SqlDataAdapter myCommand = new SqlDataAdapter("select fname from admin where fname<>'gumpgz'", myConnection);
最后最好加上
DropDownList1.DataBind();

解决方案 »

  1.   

    如果用vb.net可以这样解决
    先是在一个类中写如下的一些函数
    比如类名叫data
     Dim cnstr As String = "Persist Security Info=False;User ID=sa;pwd=;Initial Catalog=数据库名称;Data Source=机器名称"
        Function getcn() As SqlConnection
            getcn = New SqlConnection(cnstr)
        End Function
    '通过SQL得到DATAVIEW
        Function GetViewbySQL(ByVal SQLstr As String) As DataView
            Dim cn As SqlConnection
            cn = getcn()
            Dim cm As New SqlDataAdapter()
            Dim tmpdataset As New DataSet()
            Dim tmpview As New DataView()
            cn.Open()
            cm.SelectCommand = New SqlCommand(SQLstr, cn)
            cm.Fill(tmpdataset)
            tmpview.Table = tmpdataset.Tables(0)
            cn.Close()
            getviewbySQL = tmpview
            '  tmpview = Nothing
        End Function
     'DDL赋值,条件DDL,字段1(value),字段2(text),表名
        Function DDLvalue(ByVal Field1 As String, ByVal Field2 As String, ByVal TableName As String) As DropDownList
            Dim tmpsql As String
            Dim sel As New DropDownList()
            Dim tmpview As New DataView()
            tmpsql = "select " & Field1 & "," & Field2 & " from " & TableName
            tmpview = GetViewbySQL(tmpsql)
            sel.DataValueField = Field1
            sel.DataTextField = Field2
            sel.DataSource = tmpview
            sel.DataBind()
            DDLvalue = sel
        End Function
    然后再页面上调用该类
     Dim classdm As New data()
     If Not Page.IsPostBack Then
                sel_CustCode.DataSource = classdm.DDLvalue("custypcode", "custtype", "表名").DataSource
                If sel_CustCode.Items.Count > 0 Then sel_CustCode.SelectedIndex = 0
                sel_CustCode.DataBind()
            End If
    这样模块化更好,