日期:2014-05-17  浏览次数:20468 次

组合两个字符串的问题
我想将连个字符串组成起来,但是为什么其中一个字符串会提示为赋值字段?求指教?

C# code
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;}





------解决方案--------------------
探讨

引用:

sql语句有问题


用code = "mm" + code;时候断点,显示出code1是被赋值的,说明sql语句取到值了