我将数据读取到sqldatareader中了,只是如何将Read[i]中的性别赋给dropdownlist,那位高手给咱看看,小弟在此谢过!!!

解决方案 »

  1.   

    dropdownlist.DataTextField=reader["性别"].ToString();
    dropdownlist.DataBind();
      

  2.   

    你在数据库中的性别字段是什么类型呢,是varchar这种,存放“男”“女”,还是bit,存放0,1,0代表男,1代表女ALTER PROCEDURE dbo.StoredProcedure1
     /*
     (
     @parameter1 int = 5,
     @parameter2 datatype OUTPUT
     )
     */
     /*@stuNum nchar(10),*/
     @stuNum nchar(10),
     @stuName nchar(10),
     @stuPassWord nchar(10),
     @stuSex char(10),
     @stuClassNum nchar(10),
     @name nchar(10) output
     
     with encryption
     
    AS
     SET NOCOUNT off
     
     insert into student values(newid(),@stuNum,@stuName,@stuPassWord,
     case @stuSex
     when '男' then 'true'
     when '女' then 'false'
     end
     ,@stuClassNum)
     
     select stuNum,stuName from student where stuName=@stuName
     
     select @name=stuName from student
     
     RETURN @name
      

  3.   


    create table aaaa
    (
     sex varchar(22)
    )
    go
    insert into aaaa values('男')
    insert into aaaa values('男')
    go
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SqlConnection conn=new SqlConnection("server=.;uid=virus;pwd=;database=master");
                conn.Open();
                SqlCommand comm=new SqlCommand("select * from aaaa",conn);
                SqlDataReader dr=comm.ExecuteReader();
                while (dr.Read())
                {
                    this.DropDownList1.Items.Add(dr[0].ToString());
                }
                
            }
        }
    }
      

  4.   

      comboBox1.Items.Add(Read[i]);
      comboBox1.SelectedIndex = 0;
      

  5.   

    如果我的数据是读取到arraylist中,数组中的性别显示如何给dropdownlist,
      

  6.   

       还可以用绑定,简单实用
    comboBox1.DataBindings.Add(new Binding("SelectedValue", DataSet.Tables,"字段名"));
      

  7.   

    男和女我已经给出来了,如何能读取出的数据选中的是男或女,在dropdownlist中
    上面说的不是太清,见谅
      

  8.   

    唉,有这么复杂么,先在dropdownlist设好,TEXT和VALUE 比方,把TEXT设成男.女,VALRE 设成1.2,然后把读出的来数据转成
    TOSTRING()   DropDownList1.SelectedValue```
      

  9.   

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SqlConnection conn=new SqlConnection("server=.;uid=virus;pwd=;database=master");
                conn.Open();
                SqlCommand comm=new SqlCommand("select sex from aaaa",conn);
                SqlDataReader dr=comm.ExecuteReader();
                if(dr!=null)
                {while (dr.Read())
                {
                    if (dr[0].ToString().Equals("男"))
                    {
                        this.DropDownList1.Text = "男";
                    }
                    else if (dr[0].ToString().Equals("女"))
                    {
                        this.DropDownList1.Text = "女";
                    }
                }
                }
                
            }
        }
    }