我有一个网站,当您填写信息并按下提交按钮时, button1_click() 会将数据插入数据库。我有另一个按钮,它生成一个 id,在它之后获取日期和“0001”并将其填充到文本框中。如何使用服务器端代码让我的函数检查数据库中是否有 0001,如果它在数据库中,则将其放入“0002”中?我知道我需要使用参数,但我对它的工作原理以及用于更新数据库的代码感到困惑.. 这是我的代码
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("insert into John_IEP_Crossing_Dock_Shipment values('" + generateidtxt.Text + "','" + hawbtxt.Text + "','" + invrefpotxt.Text + "','" + hppartnumtxt.Text + "','" + iecpartnumtxt.Text + "','" + qtytxt.Text + "','" + bulkstxt.Text + "','" + boxplttxt.Text + "','" + rcvddatetxt.Text + "','" + statustxt.Text + "','" + carriertxt.Text + "','" + shippertxt.Text + "', '', '','','','','',GETDATE(),GETDATE())", con);
cmd.ExecuteNonQuery();
con.Close();
generateidtxt.Text = "";
hawbtxt.Text = "";
invrefpotxt.Text = "";
hppartnumtxt.Text = "";
iecpartnumtxt.Text = "";
qtytxt.Text = "";
bulkstxt.Text = "";
boxplttxt.Text = "";
rcvddatetxt.Text = "";
statustxt.Text = "";
carriertxt.Text = "";
shippertxt.Text = "";
con.Dispose();
}
protected void generateid_Click(object sender, EventArgs e)
{
generateidtxt.Text = "from DB";
}
}
这是我认为我需要使用的 sql 命令..
insert John_IEP_Crossing_Dock_Shipment (ID)
select ID = Left(max(ID),10) + '-' + RIGHT('000' + convert(varchar,convert(int,right(max(ID),4)) + 1), 4)
from John_IEP_Crossing_Dock_Shipment
where Left(ID,10) = convert(varchar(10), Getdate(),20)
select ID = Left(max(ID),10) + '-' + RIGHT('000' + convert(varchar,convert(int,right(max(ID),4)) + 1), 4)
from John_IEP_Crossing_Dock_Shipment
where Left(ID,10) = convert(varchar(10), Getdate(),20)