订单编号的查询增加(对于要不断删增的表)

本文介绍了一种基于当前日期和数据库中已有的订单编号来生成唯一订单号的方法。该方法首先获取系统的当前日期,并从数据库中选取特定字段,通过对比日期部分相同的记录,找出最大的订单编号,然后在此基础上加一生成新的订单号。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

public void add()
    {
        int i_orderID = 0;
        string s_Year = string.Format(("{0:D4}"),int.Parse(DateTime.Now.Year.ToString()));
        string s_Month = string.Format(("{0:D2}"),int.Parse(DateTime.Now.Month.ToString()));
        string s_Day = string.Format(("{0:D2}"),int.Parse(DateTime.Now.Day.ToString()));
        DataSet ds=new DataSetDA().selectData("select num from fId");
        for (int i = 0; i < ds.Tables[0].Rows.Count;i++ )
        {
            string str_Date = s_Year + s_Month + s_Day;
            string s_Date = ds.Tables[0].Rows[i]["num"].ToString().Substring(0,8);
            string s_id = ds.Tables[0].Rows[i]["num"].ToString().Substring(8,4);
            if(str_Date.Trim()==s_Date.ToString().Trim())
            {
                if (int.Parse(s_id) > i_orderID)
                {
                    i_orderID = int.Parse(s_id);
                }
            }

        }
        string s_orderID = string.Format(("{0:D4}"),i_orderID + 1);
        this.lblfreightID.Text =s_Year + s_Month+s_Day + s_orderID;
        new DataSetDA().insert("insert into fId values('"+lblfreightID.Text+"')");
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值