终于弄出来了 不容易啊
//编号的自动生成
string num = GetNum();
string NUM =num.Replace(DateTime.Today.Year.ToString() + "-", "").ToString();
int suu = Convert.ToInt32(NUM);
NUM =Convert.ToString(suu + 1);
this.ID.Text = DateTime.Today.Year + "-" + NUM.PadLeft(5, '0').ToString();
//获取数据库中最后一个病人编号
public String GetNum()
{
String Result = null;
SqlConnection conn = new SqlConnection(str);
conn.Open();
SqlCommand cmd = new SqlCommand("select top 1 ID from PatientMsg order by(ID) desc",conn);
SqlDataReader my = cmd.ExecuteReader();
if (my.Read())
{
Result = my[0].ToString();
}
conn.Close();
return Result;
}
感谢斑竹!!!再次感谢斑竹!!!