本文介绍了为什么我的记录未在数据库中更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里使用过功能,但数据未在databse中更新
请告诉我我哪里出问题了


here i have used function but the data is not updated in databse
please tell me where i go wrong


public static DataTable test(string code)
        {
           
            SqlConnection con = new SqlConnection("Data Source=SHILPA;Initial Catalog=TreeDB;Integrated Security=True");
            SqlCommand com = new SqlCommand();
            con.Open();
            DataTable dt = new DataTable();
            try
            {
               
                string queryRM = "SELECT * FROM Registration_Master WHERE sponcorid='" + code.ToString() + "'";
                dt = DBHelper.SQLHelper.getTable(queryRM.ToString());
                if (dt.Rows.Count > 0)
                {

                    DataTable dtl = new DataTable();
                    string left = "SELECT * FROM Registration_Master WHERE side='LEFT'";
                    dtl = DBHelper.SQLHelper.getTable(left.ToString());

                    int count_mem = Convert.ToInt32(dtl.Rows[0]["count_mem"]);
                    count_mem++;

                    com.Connection = con;
                    com.CommandText = "UPDATE Counter SET leftcount =" + count_mem + "";
                    com.CommandType = CommandType.Text;
                    com.ExecuteNonQuery();

                    DataTable dtr = new DataTable();
                    string right = "SELECT * FROM Registration_Master WHERE side='RIGHT'";
                    dtr = DBHelper.SQLHelper.getTable(right.ToString());
                    if (dtr.Rows.Count > 0)
                    {
                        int count1 = Convert.ToInt32(dtr.Rows[0]["count_mem"]);
                        count1++;
                        com = new SqlCommand();
                        com.Connection = con;
                        com.CommandText = "UPDATE Counter SET rightcount =" + count1 + "";
                        com.CommandType = CommandType.Text;
                        com.ExecuteNonQuery();
                    }
                    DataTable dtcount = new DataTable();
                    string query = "SELECT * FROM Counter";
                    dtcount = DBHelper.SQLHelper.getTable(query.ToString());
                    if (dtcount.Rows.Count > 0)
                    {
                        if (dtcount.Rows[0]["leftcount"] == dtcount.Rows[0]["rightcount"])
                        {
                            int count2 = Convert.ToInt32(dtl.Rows[0]["count_mem"]);
                            count2++;
                            com = new SqlCommand();
                            com.Connection = con;
                            com.CommandText = "UPDATE Counter SET sponcorcount = " + count2 + "";
                            com.CommandType = CommandType.Text;
                            com.ExecuteNonQuery();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }

        
            return dt;
        }

推荐答案


这篇关于为什么我的记录未在数据库中更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 17:12