select 的结果是
ID  值
1   A
2   B
3   C
 SqlConnection con = new SqlConnection("");
        con.Open();
        SqlCommand com=new SqlCommand("select * from banci",con);
        SqlDataReader sdr = com.ExecuteReader();
        if (sdr.Read())
        {
            TextBox1.Text = sdr.GetString(0);
     
        }
这样的话就只能得到一个值,现在我需要把得到的三个值全部赋给TEXTBOX,应该怎么写呢?

解决方案 »

  1.   

            if (sdr.Read())
            {
                TextBox1.Text += sdr.GetString(0);
         
            }
      

  2.   

            if (sdr.Read())
            {
                for(int i=0;i<select count(*) from banci,i++)
                TextBox1.Text += sdr.GetString(0);
         
            }
      

  3.   


    SqlConnection con = new SqlConnection("");
            con.Open();
       DataSet ds = new DataSet();
      SqlDataAdapter command = new SqlDataAdapter("select * from banci", connection);
                        command.Fill(ds, "ds");
    string str="";
    for(int i=0;i<ds.Table[0].Rows.Count;i++)
    {
    if(str=="")
    {
    str=ds.Tables[0].Rows[0][0].toString();
    }
    else
    {
    str=str+","+ds.Table[0].Rows[0][0].toString();}
    }
     TextBox1.Text =str
      

  4.   

    TEXTBOX里面全部获取了第一个值?
    在帮忙看看?
      

  5.   

    while(sdr.read()){
       textbox.text += sdr.getstring(0);
    }
      

  6.   

            遍历下就可以 
            SqlConnection cn = new SqlConnection("server=.;uid=sa;pwd=;database=banci");
            cn.Open();
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter("select * from banci", cn);
            da.Fill(ds,"banci");
            string str = "";
            for (int i = 0; i < ds.Tables[0].Rows.Count;i++)
            {
                if (str == "")
                {str = ds.Tables[0].Rows[0][0].ToString(); }
                else
                { 
                str+=","+ds.Tables[0].Rows[i][0].ToString();
                }
            }
            TextBox1.Text = str;
      

  7.   


    SqlConnection con = new SqlConnection("");
            con.Open();
            SqlCommand com=new SqlCommand("select * from banci",con);
            SqlDataReader sdr = com.ExecuteReader();
           while(sdr.Read())
            {
                TextBox1.Text += sdr.GetString(0);
         
            }