日期:2014-05-20  浏览次数:20878 次

C#编程自动编号问题
比如我要尾数是3位的开始编号,001,002,003,004......
因为前面是日期,即日期+自动编号
用C#怎么编写?

------解决方案--------------------
简单哈!
#region 自动编号
/// <summary>
/// 自动编号
/// </summary>
/// <param name="P_str_sqlstr">SQL语句</param>
/// <param name="P_str_table">数据表名</param>
/// <param name="P_str_tbColumn">数据表字段</param>
/// <param name="P_str_codeIndex">编号前的字符串</param>
/// <param name="P_str_codeNum">编号后面的数字</param>
/// <param name="txt">TextBox控件名</param>
public void autoNum(string P_str_sqlstr,string P_str_table,string P_str_tbColumn,string P_str_codeIndex,string P_str_codeNum,TextBox txt)
{
string P_str_Code = "";
int P_int_Code = 0;
DataSet myds = boperate.getds(P_str_sqlstr,P_str_table);
if (myds.Tables[0].Rows.Count == 0)
{
txt.Text = P_str_codeIndex + P_str_codeNum;
}
else
{
P_str_Code = Convert.ToString(myds.Tables[0].Rows[myds.Tables[0].Rows.Count - 1][P_str_tbColumn]);
P_int_Code = Convert.ToInt32(P_str_Code.Substring(2, 7)) + 1;
P_str_Code = P_str_codeIndex + P_int_Code.ToString();
txt.Text = P_str_Code;
}
}
#endregion
修改下就行了!这是我看到的