日期:2014-05-17 浏览次数:20492 次
protected string GetFormCode() { int maxValue = 0; string classname = ddlclass.Text.Trim(); string code; string code1; // using (LXS.DAL.deviceinfo.LXS db = new LXS.DAL.deviceinfo.LXS()) //DataTable dt=new DataTable (); { SqlConnection conn = new SqlConnection("Data Source=(local);Database=LOGINDB;Uid=sa;Pwd=sa123456"); SqlCommand cmd; SqlCommand cmd1; cmd = conn.CreateCommand(); cmd1 = conn.CreateCommand(); cmd.CommandText = "select max (a.deviceid)from (select deviceid from deviceinfo where classno=(select classno from class where classname='" + classname + "')) a"; cmd1.CommandText = "select classno from deviceinfo where classno=(select classno from class where classname='" + classname + "') group by classno"; conn.Open(); SqlDataReader Reader = cmd.ExecuteReader(); while (Reader.Read()) { maxValue = Convert.ToInt32(Reader[0].ToString()); } code = Convert.ToString(maxValue + 1); Reader.Close(); conn.Close(); conn.Open(); SqlDataReader Reader1 = cmd1.ExecuteReader(); while (Reader1.Read()) { code1 = Convert.ToString(Reader1[0].ToString()); } // code1 = Convert.ToString(code1); Reader.Close(); conn.Close(); // code = "mm" + code;(如果改成此句,则可以操作) code = code1+code; return code;}