显示长日期格式和显示金额格式文本

数据库连接访问都是放在数据库访问类 SqlHelper.cs类里面 这里是保证程序的完成性 所以每个操作都加上了繁琐的操作 呵呵~~~~
       SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=123456;database=Member");
        string sql = "select * from tbMember";
        //SqlCommand cmd = new SqlCommand(sql, con);
        SqlDataAdapter sda = new SqlDataAdapter(sql, con);
        DataSet ds = new DataSet();
        sda.Fill(ds, "tbMember"); //重新命名下
        this.DataList1.DataSource = ds;
        this.DataBind(); //绑定数据
        DataRowView drv = ds.Tables["tbMember"].DefaultView[0];
        for (int i = 0; i <= this.DataList1.Items.Count - 1; i++)
        {
            Label lab = (Label)this.DataList1.Items[i].FindControl("Label1");
            DateTime dt = Convert.ToDateTime(drv["date"]);
            lab.Text = dt.ToLongDateString();
        }
        //本例子主要使用DateTime对象的ToLongDateString()方法将数据库中的数据转化成长日期格式 2006年5月5日

        SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=123456;database=Member");
        string sql = "select * from tbMember";
        //SqlCommand cmd = new SqlCommand(sql, con);
        SqlDataAdapter sda = new SqlDataAdapter(sql, con);
        DataSet ds = new DataSet();
        sda.Fill(ds, "tbMember"); //重新命名下
        this.DataList1.DataSource = ds;
        this.DataBind(); //绑定数据
        DataRowView drv = ds.Tables["tbMember"].DefaultView[0];
        for (int i = 0; i <= this.DataList1.Items.Count - 1; i++)
        {
            Label lab = (Label)this.DataList1.Items[i].FindControl("Label2");
            int money = Convert.ToInt32(drv["money"]);
            lab.Text = money.ToString();
        }
        //int.Tostring(string format) 方法表示使用指定格式,将实例数值转化为它的等效字符串格式

明天再做详细解释

原文地址:https://www.cnblogs.com/ivy/p/1214008.html