本文介绍了如何简单地每天生成id与系统日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一天的代码,

code for one day,

int i;
string str;
SqlConnection cn = null;
protected void Page_Load(object sender, EventArgs e)
   {
         cn = new
     SqlConnection(ConfigurationManager.ConnectionStrings["concms"].ConnectionString);
        cn.Open();
        txtdate.Text = Convert.ToDateTime(date).ToString("dd-MM-yyyy");
        DataTable dt = new DataTable();
        SqlDataAdapter da = new SqlDataAdapter("select max(substring(complainid,10,3))
                  from newcomplainuser where dates =''" + txtdate.Text.ToString()+"''",
                  cn);
        da.Fill(dt);
        str = da.SelectCommand.ExecuteScalar().ToString() ;
        i = Convert.ToInt32(str) + 1 ;
        txtcomplain.Text = Convert.ToDateTime(date).ToString("ddMMyyyy" + "-" + i );
        cn.close();
}


输出:
27032012-1
27032012-2
27032012-3 ........ 27032012-n

现在,我该如何生成第二天... ??

第二天的输出将是28032012-1、28032012-2 ..依此类推..

请告诉您您的建议...


output:
27032012-1
27032012-2
27032012-3........ 27032012-n

now, how can i generate for second day ...??

second day output will be 28032012-1, 28032012-2.. so on..

please tell your suggestion...

推荐答案

using(SqlConnection conn = new SqlConnection(...))
{

}



这没道理



This makes no sense

txtdate.Text = Convert.ToDateTime(date).ToString("dd-MM-yyyy");


您正在将某个字符串转换为日期,然后再转换回字符串,仅是将其分配给文本框.然后,在SqlCommand中使用该文本框值.直接使用字符串.


You are converting some string to a date then back to a string only to assign it to a textbox. Then later using that textbox value in the SqlCommand. Use the string directly.

txtdate.Text.ToString()


text属性已经是一个字符串.您不需要在字符串上使用ToString.

请勿将其放在Page_Load事件中.


The text property is already a string. You don''t need to use ToString on a string.

Don''t put this in the Page_Load event.



这篇关于如何简单地每天生成id与系统日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 22:39