各位大虾 怎么实现自动编号 这个编号是单据号 就是当前时间+号码 2011-12-25-0001如果是第二天变成2011-12-26-0001编号又从0001开始 各位大虾帮帮忙 急啊
解决方案 »
- js里面这种写法什么意思??迷惑中~~~~~~~不知道自己理解错没
- 在ImageMap中显示图片中出现的问题
- 请问web2.0到底是什么东东?
- realplay播放器,我怎么样才能把参数传给它
- 新手的弱弱问题,请各位别鄙视偶!偶像学,谢谢了!!!
- asp.net的cms比较好用的模板有哪些?比如jtbc
- 紧急求助!上传图片问题!
- 哪位大侠,有c# 的 新闻发布的代码(主要是 新闻内容的 图片 和文字的 混合在一起的)
- gridview绑定,如果T1这一列中的某一行的值为15:00,则这一单元格不显示内容,为空
- EF Core在代码里面记录生成的Sql语句
- 在asp.net中,用js控制windows media player,实现连续播放代码
- gridview连接数据库出错,求大神解决
或在sql里使用getdate生成编号
给你一个使用触发器的样例:ALTER TRIGGER [dbo].[Trigger_Insert]
ON [dbo].[TableA]
After INSERT
AS
BEGIN
declare @pkid int,@pid varchar(14),@temppid varchar(14)
--从Inserted表中取得主键的自动编号
select @pkid=pkid from Inserted
--获取当前日期格式为"P20081010"
select @pid = 'P' + Convert(varchar(8),GetDate(),112);
--获取最后一个PID
select top 1 @temppid=pid from TableA where pid like @pid+'%' order by pkid desc
if (@temppid is null)
begin
--如果今天没有插入过数据,则初始值为'P200810100001'
set @pid = @pid + '0001'
end
else
begin
--否则从最后一个日期取得编号,并末尾加上1,组成新编号
set @pid = @pid + right(cast(power(10,4) as varchar)+(convert(int,substring(@temppid,10,4))+1),4)
end
--更新编号
update TableA set pid=@pid where pkid = @pkid
END
http://www.cnblogs.com/insus/archive/2011/08/21/2147645.html
{
System.DateTime da = System.DateTime.Now;
string dtime = Convert.ToString(da);
string stime = dtime.Substring(0, 10);
// t4.Text = stime; string sql1 = "select * from t_bill where billcode like '%" + stime + "%'"; SqlConnection conn1 = new SqlConnection(sqlconn);
SqlCommand cmd1 = new SqlCommand(sql1, conn1);
conn1.Open();
if (cmd1.ExecuteScalar() != null)
{
//Response.Write(cmd1.ExecuteScalar().ToString());
SqlDataReader dr = cmd1.ExecuteReader(); dr.Read();
string bcode = Convert.ToString(dr["billcode"]).Substring(14, 4); Autocode(bcode); }
else
{
t1.Text = "xf" + "-" + stime + "-" + "0001";
}
}
{
System.DateTime da = System.DateTime.Now;
string dtime = Convert.ToString(da);
string stime = dtime.Substring(0, 10); int billcode = Convert.ToInt32(code) + 1;
// Response.Write(billcode);
string scode = Convert.ToString(billcode);
if (scode.ToString().Length == 1)
{
t1.Text = "xf" + "-" + stime + "-" + "000" + scode;
string code11 = t1.Text.Substring(14, 4); // Response.Write(code);
//Autocode(bcode);
}
if (scode.ToString().Length == 2)
{
t1.Text = "xf" + "-" + stime + "-" + "00" + scode;
}
if (scode.ToString().Length == 3)
{
t1.Text = "xf" + "-" + stime + "-" + "0" + scode;
} }