怎么向它添加选项
我的代码问题在那里啊
SQL数据查询是正确的我验证过的
但是我运行后 下拉框里面一片空白!!!!
代码:
                      SqlConnection sqlcon=new SqlConnection(con);
sqlcon.Open();
DataSet ds=new DataSet();
try
{
SqlDataAdapter da=new SqlDataAdapter(dutySelect,sqlcon);
 da.Fill(ds,"AT_Duty");
                 DropDownList1.DataSource=ds.Tables["AT_Duty"].DefaultView;
 DropDownList1.DataValueField=ds.Tables["AT_Duty"].Rows[0][0].ToString();  DropDownList1.DataBind();
sqlcon.Close();
}
catch(System.Exception ex)
{
Console.WriteLine("the error:"+ex.Message.ToString());
}
finally
{
}

解决方案 »

  1.   

    DropDownList1.DataValueField=ds.Tables["AT_Duty"].Rows[0][0].ToString();
    改为 
    DropDownList1.DataValueField=ds.Tables[0].Columns[0].ColumnName;试试看
      

  2.   

    可以用一个循环实现!
    dim i as integer
    dim s as stringfor i= 0 to ds.table(0).row.count-1s= ds.table(0).row(i).item("字段名")
    DropDownList1.Items.Insert(i, s)next i
      

  3.   

    DropDownList1.DataValueField="字段A";
    DropDownList1.DataTextField="字段B";
      

  4.   

    DropDownList1.DataSource=ds.Tables["AT_Duty"];
    DropDownList1.DataValueField="字段A";
    DropDownList1.DataTextField="字段B";这样写就行了。
      

  5.   

    string Conn= ConfigurationSettings.AppSettings.Get("Con");
    SqlConnection myconn=new SqlConnection(Conn);
    string sql="select 字段A,字段B from 表";

    DataTable DT=new DataTable();
    SqlDataAdapter SDA=new SqlDataAdapter(sql,myconn);
    SDA.Fill(DT);DropDownList1.DataSource=DT.DefaultView;
    DropDownList1.DataTextField="字段A";
    DropDownList1.DataValueField="字段B";
    DropDownList1.DataBind();