我这个程序很卡,还有如果有错误就停止了,怎么弄就不卡了,有错误就不停止了,帮忙弄下,谢谢,小弟是新到的没多少分,谢谢private void button1_Click(object sender, EventArgs e)
        {
            if (this.button1.Text == "检测")
            {
                try
                {
                    string sql = "select top(1) * from NBMM_MARC_DATA";
                    Datas d = new Datas();
                    using (DataTable table = DBHelper.GetDataSet(sql))
                    {
                        foreach (DataRow row in table.Rows)
                        {
                            d.Marccontent = Convert.ToString(row["MARCIDENTITY"]);
                            d.Marcidentity = Convert.ToString(row["MARCCONTENT"]);
                        }
                    }
                }
                catch (Exception eee)
                {
                    
                    string ee = eee.ToString();
                    MessageBox.Show("错误:" + ee);
                }
             
                               //this.label1.Text = "Identity:" + d.Marccontent;
                int butong = butongshuju();
                this.label2.Text = "不同的个数:" +butong;
                if (butong > 0)
                {
                    this.button1.Text = "开始";
                }
            }
            else  if(this.button1.Text=="开始"){
                int k=update();
                if (k > 0) {
                    MessageBox.Show("成功!");
                    this.label2.Text = "不同的个数:0" ;
                }
                this.button1.Text = "检测";
            }
        }
        //检测有多少条不同数据
        public int butongshuju() {
            int num = 0;
            int dataNull = 0;
            string sql = "select * from NBMM_MARC_DATA";
            List<Datas> list = new List<Datas>();
            try
            {
                using (DataTable table = DBHelper.GetDataSet(sql))
                {
                    foreach (DataRow row in table.Rows)
                    {
                        Datas d = new Datas();
                        d.Marccontent = Convert.ToString(row["MARCIDENTITY"]);
                        d.Marcidentity = Convert.ToString(row["MARCCONTENT"]);
                        list.Add(d);
                    }
                }
                for (int i = 0; i < list.Count; i++)
                {
                    Datas d2 = new Datas();
                    d2 = list[i];
                    if (d2.Marcidentity != "")
                    {
                        int weishu = d2.Marcidentity.IndexOf("Identity=\"");
                        string weishutext = "Identity=\"";
                        int geshu = 0;
                        for (int j = weishu + weishutext.Length; j < d2.Marcidentity.Length; j++)
                        {
                            string kk = d2.Marcidentity.Substring(j, 1);
                            if (!kk.Equals("\""))
                            {
                                geshu = geshu + 1;
                            }
                            else
                            {
                                break;
                            }
                            Application.DoEvents();
                        }
                        string bijiaozhiduan = d2.Marcidentity.Substring(d2.Marcidentity.IndexOf("Identity=\"") + "Identity=\"".Length, geshu);
                        if (bijiaozhiduan != d2.Marccontent)
                        {
                            num = num + 1;
                        }
                    }
                    else
                    {
                        dataNull = dataNull + 1;
                    }
                    Application.DoEvents();
                }
            }
            catch (Exception eee) {
            //    throw (eee);
            }
            this.label3.Text = "有"+dataNull+"条空数据";
                return num;
        }
        //修改数据 
        public int update() {
            int upnum = 0;
            ///try{
            string sql = "select * from NBMM_MARC_DATA";
            List<Datas> list = new List<Datas>();
            try
            {
                using (DataTable table = DBHelper.GetDataSet(sql))
                {
                    foreach (DataRow row in table.Rows)
                    {
                        Datas dx = new Datas();
                        dx.Marccontent = Convert.ToString(row["MARCIDENTITY"]);
                        dx.Marcidentity = Convert.ToString(row["MARCCONTENT"]);
                        list.Add(dx);
                    }
                }
            }
            catch (Exception e)
            {
                //throw (e);
            }
            try
            {
            for (int i = 0; i < list.Count; i++)
            {
                Datas dx2 = new Datas();
                dx2 = list[i];
                if (dx2.Marcidentity != "")
                {
                    int weishu = dx2.Marcidentity.IndexOf("Identity=\"");
                    string weishutext = "Identity=\"";
                    int geshu = 0;                    for (int j = weishu + weishutext.Length; j < dx2.Marcidentity.Length; j++)
                    {
                        string kk = dx2.Marcidentity.Substring(j, 1);
                        if (!kk.Equals("\""))
                        {
                            geshu = geshu + 1;
                        }
                        else
                        {
                            break;
                        }
                        Application.DoEvents();
                    }
                    string bijiaozhiduan = dx2.Marcidentity.Substring(dx2.Marcidentity.IndexOf("Identity=\"") + "Identity=\"".Length, geshu);
                    if (bijiaozhiduan != dx2.Marccontent)
                    {
                        string kaishi = dx2.Marcidentity.Substring(0, weishu + "Identity=\"".Length) + dx2.Marccontent;
                        string jishu = dx2.Marcidentity.Substring(weishu + "Identity=\"".Length + bijiaozhiduan.Length, dx2.Marcidentity.Length - (weishu + "Identity=\"".Length + bijiaozhiduan.Length));
                        string quanbu = kaishi + jishu;
                        this.richTextBox1.Text = this.richTextBox1.Text + dx2.Marccontent + "更新......\n";
                        string sql2 = "update NBMM_MARC_DATA set MARCCONTENT='" + quanbu + "' where MARCIDENTITY='" + dx2.Marccontent + "'";
                        int tex = DBHelper.ExecuteCommand(sql2);
                        if (tex > 0)
                        {
                            upnum = upnum + 1;
                        }
                    }
                    Application.DoEvents();
                }
           
            }
            }
            catch (Exception eee)
            {
              // throw(eee);
             
         }
            return upnum;
        }