您的位置:首页 > 其它

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

2008-06-05 01:01 295 查看
数据库连接访问都是放在数据库访问类 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) 方法表示使用指定格式,将实例数值转化为它的等效字符串格式

明天再做详细解释
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: