Sda.SelectCommand.CommandText = "select count(*) as iCount from bo "
我想把值放到label中 该怎么写?  谢谢

解决方案 »

  1.   

    SqlDataAdapter da=new SqlDataAdapter("select count(*) as iCount from bo ",conn);
    datas ds=new dataset();
    ds.fill(ds,"aa");
    this.label1.text=ds.tabel("aa").row[0][0].tostring();
      

  2.   

     string sConnection = "";
     DataSet ds = new DataSet();
    SqlDataAdapter sd= null;
    SqlConnection con= new SqlConnection(sConnection);
    SqlCommand cmd= con.CreateCommand();
    scCommand.CommandText = "select count(*) as iCount from bo ";
    sdaAdapter = new SqlDataAdapter(cmd);
    sdaAdapter.Fill(ds);this.label1.Text=ds.Table[0].Rows[0]["iCount "].ToString();         
      

  3.   


            private void Form1_Load(object sender, EventArgs e)
            {
                SqlDataAdapter Sda = new SqlDataAdapter();
                DataSet ds = new DataSet();
                Sda.SelectCommand.CommandText = "select count(*) as iCount from bo ";
                Sda.Fill(ds);
                label1.Text = ds.Tables[0].Rows[0].ItemArray[0].ToString();
            }
      

  4.   

    label1.Text = ds.Tables[0].Rows[0].ItemArray[0].ToString();
      

  5.   

    我们公司框架的做法是使用自定义控件里面有两个属性,一个是对应的表名,一个是字段名
    然后使用一个方法来SET一个控件的值
    MyLabel.cs[ToolboxData("<{0}:MyLabel runat=server CssClass=\"myLabel\"></{0}:MyLabel>")]
        public class MyLabel : Label
        {
            //对应的字段名
            [Category("Appearance"), Browsable(true), Description("TextMappingField")]
            public string TextMappingField
            {
                get
                {
                    return (ViewState["TextMappingField"] == null ?
                        "" : (string)ViewState["TextMappingField"]);
                }
                set
                {
                    ViewState["TextMappingField"] = value;
                }
            }        //对应的表名
            [Category("Appearance"), Browsable(true), Description("ModelName")]
            public string ModelName
            {
                get
                {
                    return (ViewState["ModelName"] == null ?
                        "" : (string)ViewState["ModelName"]);
                }
                set
                {
                    ViewState["ModelName"] = value;
                }
            }
        }    private static void SetControlsValues(Control ctl, IModel model)
        {
            foreach (Control c in ctl.Controls)
            {
                try
                {
                     if (c is MyLabel && ((MyLabel)c).ModelName.ToUpper().Trim() == model.GetType().Name.ToUpper().Trim())
                    {
                        MyLabel mtb = (MyLabel)c;
                        if (mtb.ValidType == MyLabel.AvailableType.DateTime)
                        {
                            //DaoUtility.GetPropertyValue()是一个用来通过实体和该实体的属性名称来获得该实体的该属性的值的方法
                            string text = DaoUtility.GetPropertyValue(model, mtb.TextMappingField).ToString();
                            string dtText = Convert.ToDateTime(text).ToString("yyyyMMdd");
                            mtb.Value = text;
                        }
                }
         }          /// <summary>
            /// 获取对象中的一个属性的值
            /// </summary>
            /// <param name="model">对象</param>
            /// <param name="propertyName">属性名称</param>
            /// <returns>属性的值</returns>
            public static object GetPropertyValue(object model, string propertyName)
            {           
                 object asyn = new object();
                 lock (asyn)
                 {
                     PropertyInfo prop = model.GetType().GetProperty(propertyName);
                     if (prop == null)
                         return null;
                     object result = prop.GetValue(model, null);                 return result;
                 }
            }
      

  6.   

    同样,TextBox, COMBOBOX, CheckBox也可以用同样的方法
    这样的好处是所有的控件的值就只需要一个方法来给他设置其Value了当然,你也可以再写个方法来获取这些控件的值,用来保存编辑和用户输入的结果.
    这就是自定义控件的好处,不过这原理有点模仿了JAVA的Struts标签,欢迎一同探讨研究
      

  7.   

    <cc1:MyTextBox ID="txtVoyage" runat="server" CssClass="textBoxReadonly" ModelName="V_TM_BL_PaymentList"
    TextMappingField="Voyage" Width="50px"></cc1:MyTextBox>这个是使用的例子
      

  8.   

    Sda.SelectCommand.CommandText = "select count(*) from bo " ;
    int getValue=(int) SelectCommand.ExecuteScalar();
    getValue 就是你查询的结果,你想怎么用就怎么用。。
      

  9.   

    System.Reflection.PropertyInfo类:发现属性 (Property) 的属性 (Attribute) 并提供对属性 (Property) 元数据的访问。