我很难弄清楚该怎么做。我想做的是..
例如:
日期:2018年10月1日至2018年10月31日,有2条记录,您可以在提供的图像上看到这些记录。您可以看到ID以001开始,依此类推。下个月是11月。ID应该重新启动/返回到001,而不是003。
PS:我数据库中的OrderID是VARCHAR数据类型
我希望有人能够帮助我
public partial class SIMSSupplier : UserControl
{
ADDPOrders order;
public SIMSSupplier()
{
InitializeComponent();
}
public string ORDERID = "000";
private void ADDOrder_Click(object sender, EventArgs e)
{
order = new ADDPOrders(this);
POrderID._OrderID(order.lbl_orderID);
order.ShowDialog();
}
private void DateOrder_ValueChanged(object sender, EventArgs e)
{
DateBetween._DateOrder(DateOrder, DateOrder, PurchaseOrder);
}
private void DateOrder2_ValueChanged(object sender, EventArgs e)
{
DateBetween._DateOrder(DateOrder, DateOrder2, PurchaseOrder);
}
}
public static class DateBetween
{
public static void _DateOrder(DateTimePicker DateOrder, DateTimePicker DateOrder2, DataGridView PurchaseOrder)
{
using (var con = SQLConnection.GetConnection())
{
using (var select = new SqlCommand("Select * from Purchase_Order where Date between @date1 and @date2", con))
{
select.Parameters.Add("@date1", SqlDbType.Date).Value = DateOrder.Value;
select.Parameters.Add("@date2", SqlDbType.Date).Value = DateOrder2.Value;
using (var sd = new SqlDataAdapter(select))
{
var dt = new DataTable();
sd.Fill(dt);
PurchaseOrder.DataSource = dt;
}
}
}
}
}
答案 0 :(得分:1)
If you have the possibility to change the field type to int is much easier to do this from SQL directly. You can auto increment and change the change the seed value each month with a script like the one below (note it also adds the month number in the beginning, if that's useful for you):
IF (DATEPART(DAY, GETDATE()) = 1)
BEGIN
DECLARE @reseedValue INT
SET @reseedValue = CAST(CONCAT(CAST(DATEPART(MONTH, GETDATE()) AS NVARCHAR(4)), '000') AS INT)
DBCC CHECKIDENT ('[table_name]', RESEED, @reseedValue);
END