2009年3月17日 星期二

[C#] IF內部的變數,如果外部要使用的時候 小技巧(書裡面沒教的)

原本

                           
                            if (result.Rows.Count == 0)
                            {

                             km.SQLExecute("INSERT INTO MGMES.dbo.PACKAGE_SN_FILL() VALUE () ");
                            }
                            else
                            {
                                 String show5_4_1 = result.Rows[0].ItemArray[0].ToString();
                               
                            }
                          
                            string show5_4_1_ADD1 = show5_4_1.Substring(1, 5); //這時候 show_5_4_1 不能使用




改成



                            string show5_4_1="";
                           
                            if (result.Rows.Count == 0)
                            {

                                km.SQLExecute("INSERT INTO MGMES.dbo.PACKAGE_SN_FILL() VALUE () ");
                            }
                            else
                            {
                                 show5_4_1 = result.Rows[0].ItemArray[0].ToString();
                               
                            }
                          
                            string show5_4_1_ADD1 = show5_4_1.Substring(1, 5); //可以使用了

沒有留言:

張貼留言