string .format 生成类似20090409001的序号

string sUsername = "";
string date = DateTime.Now.ToString("yyyyMMdd");
        DataTable dtmax = Conn.query("select sUserName from xUser where sUserName like '" + date + "%' order by sUserName desc ");

if (dtmax.Rows.Count == 0)

        sUsername = date + "001";
else

        sUsername =date +String .Format ("{0:D3}", (Convert.ToInt32(dtmax.Rows[0]    ["sUserName"].ToString().Substring(7)) + 1));
        txtsUserName.Text = sUsername;

posted @ 2009-04-11 16:19  refuly  阅读(192)  评论(0编辑  收藏  举报