Repeater遍历每个项目的问题

时间:2015-09-22 21:08:09

标签: c# asp.net repeater

我遇到循环访问我的转发器以保存所有数据的问题。如果我在转发器中有30个项目,它将通过转发器30次。但是,ID永远不会更新。我将id设置为文本框,因此我知道DB的值是正确的而不是重复的。

这是我的代码。

 protected void Save()
{

    foreach (RepeaterItem RI in Repeater1.Items)
    {

            bool budgetvalue = CBBudgeted.Checked;
            //lblHeader.Text = rs["BudgetYear"].ToString();
            string Janbudget = txtJanBudget.Text;
            string Febbudget = txtFebBudget.Text;
            string Marbudget = txtMarBudget.Text;
            string Aprbudget = txtAprBudget.Text;
            string Maybudget = txtMayBudget.Text;
            string Junbudget = txtJunBudget.Text;
            string Julbudget = txtJulBudget.Text;
            string Augbudget = txtAugBudget.Text;
            string Sepbudget = txtSepBudget.Text;
            string Octbudget = txtOctBudget.Text;
            string Novbudget = txtNovBudget.Text;
            string Decbudget = txtDecBudget.Text;
            string PriceEach = txtPriceEach.Text;
            string IDnum = txtID.Text;
            string saveStaff = "Update sales_budget " +
                               "set Janbudget " + Janbudget +
                               ", Febbudget " + Febbudget +
                               ", Marbudget " + Marbudget +
                               ", Aprbudget " + Aprbudget +
                               ", Maybudget " + Maybudget +
                               ", Junbudget " + Junbudget +
                               ", Julbudget " + Julbudget +
                               ", Augbudget " + Augbudget +
                               ", Sepbudget " + Sepbudget +
                               ", Octbudget " + Octbudget +
                               ", Novbudget " + Novbudget +
                               ", Decbudget " + Decbudget +
                               ", Budget " + budgetvalue +
                               ", Price_Each " + PriceEach +
                               " Where id = " + IDnum;

            GetConnection Sales = new GetConnection();
            string conn = Sales.SalesConnect;
            SqlCommand querySaveStaff = new SqlCommand(saveStaff);
            using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(conn))
            {
                System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand(saveStaff, con);
                con.Open();
                try
                {
                    command.ExecuteNonQuery();
                }
                catch
                {
                    //GetConnection Sales = new GetConnection();
                    //       string conn = Sales.SalesConnect;


                    //       using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(conn))
                    //       {
                    //           System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand(mysql, con);
                    //           con.Open();
                    //           System.Data.SqlClient.SqlDataReader rs = command.ExecuteReader();

                    //           while (rs.Read())
                }
                con.Close();
            }
        }

0 个答案:

没有答案