string str = ""; string code = ""; //取出需要编号列的最大值 string sqlstring = "select MAX(BH) from dbo.adminuser"; //调用sql操作的公共类 DataTable tbs = db.GetTable(sqlstring); str = Convert.ToString(tbs.Rows[0][0]); if(str !=null && str!="") { //从第二位后截取字符 string tmp = str.Substring(2); //截取前两个字符 string bb = str.Substring(0, 2); for(int i =1;i<=1;i++) { string num = Convert.ToString(Convert.ToInt32(tmp) + i); //详情见同目录 PadLeft,填充 num = num.PadLeft(3, '0'); code = bb + num; } } else { code = "BH001"; }