用C#写一个自增序号的程序,实现对序号的自动增加。
1个回答
2018-01-02 · 百度知道官方认证企业
腾讯电脑管家
腾讯电脑管家是腾讯公司推出的免费安全管理软件,能有效预防和解决计算机上常见的安全风险,并帮助用户解决各种电脑“疑难杂症”、优化系统和网络环境,是中国综合能力最强、最稳定的安全软件。
向TA提问
关注
展开全部
给你个例子参考下:
public string GetAutoDocNo()
{
string DocNo = "AD";
string today = DateTime.Today.Date.ToString("yyyyMMdd", DateTimeFormatInfo.InvariantInfo);
DataSet DocDs = GetDataSet(" select * from News");
//初始化
if (DocDs.Tables[0].Rows.Count == 0)
{
DocNo += today + "101";
return DocNo;
}
/***********************/
else if (DocDs.Tables[0].Rows.Count > 0)
{
int count = 0;
string oldDocNo = string.Empty;
for (int i = 0; i < DocDs.Tables[0].Rows.Count; i++)
{
oldDocNo = DocDs.Tables[0].Rows[i]["NewsID"].ToString();
oldDocNo = oldDocNo.Substring(2, 8);
if (oldDocNo == today) count++;
}
if (count == 0/*当天还没有单*/)
{
DocNo += today + "1001";//前面有1比较方便,没有1在后面做的时候要稍微再加几行代码
return DocNo;
}
else if (count > 0/*当天已经有单*/)
{
DocDs = GetDataSet("select MAX(CAST(SUBSTRING(NewsID,3,12) AS BIGINT)) as NewsID from News where
(SUBSTRING(NewsID,3,8))='" + today + "'");
string id = DocDs.Tables[0].Rows[0]["NewsId"].ToString();
string lastid = id.Substring(8, 3);
try
{
decimal lastidec = decimal.Parse(lastid);
lastidec += 1;
return DocNo + today + (lastidec.ToString());
}
catch (Exception)
{
throw;
}
public string GetAutoDocNo()
{
string DocNo = "AD";
string today = DateTime.Today.Date.ToString("yyyyMMdd", DateTimeFormatInfo.InvariantInfo);
DataSet DocDs = GetDataSet(" select * from News");
//初始化
if (DocDs.Tables[0].Rows.Count == 0)
{
DocNo += today + "101";
return DocNo;
}
/***********************/
else if (DocDs.Tables[0].Rows.Count > 0)
{
int count = 0;
string oldDocNo = string.Empty;
for (int i = 0; i < DocDs.Tables[0].Rows.Count; i++)
{
oldDocNo = DocDs.Tables[0].Rows[i]["NewsID"].ToString();
oldDocNo = oldDocNo.Substring(2, 8);
if (oldDocNo == today) count++;
}
if (count == 0/*当天还没有单*/)
{
DocNo += today + "1001";//前面有1比较方便,没有1在后面做的时候要稍微再加几行代码
return DocNo;
}
else if (count > 0/*当天已经有单*/)
{
DocDs = GetDataSet("select MAX(CAST(SUBSTRING(NewsID,3,12) AS BIGINT)) as NewsID from News where
(SUBSTRING(NewsID,3,8))='" + today + "'");
string id = DocDs.Tables[0].Rows[0]["NewsId"].ToString();
string lastid = id.Substring(8, 3);
try
{
decimal lastidec = decimal.Parse(lastid);
lastidec += 1;
return DocNo + today + (lastidec.ToString());
}
catch (Exception)
{
throw;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询