本文介绍了为什么我的count_mem没有增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个函数,我想递增count_mem,但是它无法仅递增1次增量

请检查代码,并告诉我我哪里出错了.


i have created a function in that i want to increment count_mem but it fails to increment only 1st time increment

please check the code and tell me where i go wrong..


private void testsidecount(string code)
   {

       con.Open();

       com = new SqlCommand("SELECT COUNT(*) FROM Registration_Master WHERE sponcorid='" + code + "'", con);
       int count = (int)com.ExecuteScalar();
       SqlDataAdapter da = new SqlDataAdapter();
       try
       {
           if (count == 2)
           {
               int presentCount = 0;
               presentCount++;

               SqlCommand comm = new SqlCommand();
               comm.Connection = con;
               comm.CommandText = "UPDATE Registration_Master SET count_mem = '" + presentCount + "' ,modifieddate='" + DateTime.Now + "' WHERE regCode = '" + code + "'";
               comm.CommandType = CommandType.Text;
               comm.ExecuteNonQuery();

               if ((sponcorL2.Text != "Blank") && (sponcorR3.Text != "Blank"))
               {
                   int temp = 0;
                   temp = presentCount + 1;

                   comm = new SqlCommand();
                   comm.Connection = con;
                   comm.CommandText = "UPDATE Registration_Master SET count_mem='" + temp + "' WHERE sponcorid='" + sponcor + "'";
                   comm.CommandType = CommandType.Text;
                   comm.ExecuteNonQuery();

                   if ((SponcorL4.Text != "Blank") && (sponcorR7.Text != "Blank"))
                   {
                       int temp1 = 3;

                       com.Connection = con;
                       com.CommandText = "UPDATE Registration_Master SET count_mem='" + temp1 + "' WHERE sponcorid='" + sponcor + "'";
                       com.CommandType = CommandType.Text;
                       com.ExecuteNonQuery();
                       if ((sponcorL8.Text != "Blank") && (sponcorR15.Text != "Blank"))
                       {
                           string count4 = "";
                           count4 = "4";
                           com.Connection = con;
                           com.CommandText = "UPDATE Registration_Master SET count_mem='" + count4 + "' WHERE sponcorid='" + sponcor + "'";
                           com.CommandType = CommandType.Text;
                           com.ExecuteNonQuery();
                           if ((sponcorL16.Text != "Blank") && (sponcorR31.Text != "Blank"))
                           {
                               string count5 = "";
                               count5 = "5";
                               com.Connection = con;
                               com.CommandText = "UPDATE Registration_Master SET count_mem='" + count5 + "' WHERE sponcorid='" + sponcor + "'";
                               com.CommandType = CommandType.Text;
                               com.ExecuteNonQuery();
                               if ((sponcorL32.Text != "Blank") && (sponcorR63.Text != "Blank"))
                               {
                                   string count6 = "";
                                   count6 = "6";
                                   com.Connection = con;
                                   com.CommandText = "UPDATE Registration_Master SET count_mem='" + count6 + "' WHERE sponcorid='" + sponcor + "'";
                                   com.CommandType = CommandType.Text;
                                   com.ExecuteNonQuery();
                                   if ((sponcorL64.Text != "Blank") && (sponcorR127.Text != "Blank"))
                                   {
                                       string count7 = "";
                                       count7 = "7";
                                       com.Connection = con;
                                       com.CommandText = "UPDATE Registration_Master SET count_mem='" + count7 + "' WHERE sponcorid='" + sponcor + "'";
                                       com.CommandType = CommandType.Text;
                                       com.ExecuteNonQuery();
                                       if ((sponcorL128.Text != "Blank") && (sponcorR255.Text != "Blank"))
                                       {
                                           string count8 = "";
                                           count8 = "8";
                                           com.Connection = con;
                                           com.CommandText = "UPDATE Registration_Master SET count_mem='" + count8 + "' WHERE sponcorid='" + sponcor + "'";
                                           com.CommandType = CommandType.Text;
                                           com.ExecuteNonQuery();
                                           if ((sponcorL256.Text != "Blank") && (sponcorR511.Text != "Blank"))
                                           {
                                               string count9 = "";
                                               count9 = "9";
                                               com.Connection = con;
                                               com.CommandText = "UPDATE Registration_Master SET count_mem='" + count9 + "' WHERE sponcorid='" + sponcor + "'";
                                               com.CommandType = CommandType.Text;
                                               com.ExecuteNonQuery();
                                               if ((sponcorL512.Text != "Blank") && (sponcorR1023.Text != "Blank"))
                                               {
                                                   string count10 = "";
                                                   count10 = "10";
                                                   com.Connection = con;
                                                   com.CommandText = "UPDATE Registration_Master SET count_mem='" + count10 + "' WHERE sponcorid='" + sponcor + "'";
                                                   com.CommandType = CommandType.Text;
                                                   com.ExecuteNonQuery();
                                               }
                                           }
                                       }
                                   }
                               }

                           }
                       }

                   }
               }
           }



       }
       catch (Exception ex)
       {
           throw ex;
       }
       finally
       {
           con.Close();
       }


   }



[edit]添加了代码块-OriginalGriff [/edit]



[edit]Code block added - OriginalGriff[/edit]

推荐答案


这篇关于为什么我的count_mem没有增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 09:15