protected void btnMoveps_Click(object sender, EventArgs e) { DataSet ds = new DataSet(); DataTable dt = new DataTable(); DataTable dt1 = new DataTable(); DataTable dt_ps = new DataTable(); DataTable dt_tmp = new DataTable(); string[] ps = new string[10] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }; dt_ps.Columns.Add("ps_scale", typeof(string)); dt_ps.Columns.Add("ps_price_level", typeof(string)); dt_ps.Columns.Add("ps_engt_id", typeof(string)); dt_ps.Columns.Add("ps_seats_single", typeof(string)); dt_ps.Columns.Add("ps_t_price_single", typeof(string)); dt_ps.Columns.Add("ps_scheduletype", typeof(string)); MasterDataLayer.MasterData objmst = new MasterDataLayer.MasterData(); ds = objmst.GetTempData(); dt = ds.Tables[0].DefaultView.ToTable(true, "TotPrice", "recordID"); string engtid = "", totprice = "", temp_engt_id = ""; dt1 = dt_ps.Clone(); for (int i = 0, n = 0; i < dt.Rows.Count; i++, n++) { if (temp_engt_id != dt.Rows[i]["recordid"].ToString()) { n = 0; } temp_engt_id = dt.Rows[i]["recordid"].ToString(); dt1 = dt_ps.Clone(); engtid = dt.Rows[i]["recordID"].ToString(); totprice = dt.Rows[i]["TotPrice"].ToString(); dt_tmp = ds.Tables[0].Select("recordid=" + engtid + " and TotPrice=" + totprice).CopyToDataTable(); for (int j = 0; j < dt_tmp.Rows.Count; j++) { for (int k = 0; k < 10 && j == 0; k++) { DataRow dr = dt1.NewRow(); dr["ps_seats_single"] = dt_tmp.Rows[0]["SCALE" + (k + 1).ToString() + "TICKET"].ToString(); dr["ps_t_price_single"] = dt_tmp.Rows[0]["Scale" + (k + 1).ToString() + "price"].ToString(); dr["ps_engt_id"] = engtid; dr["ps_scale"] = "A"; dr["ps_price_level"] = ps[k]; dr["ps_scheduletype"] = dt_tmp.Rows[0]["schedule_type"].ToString(); if (string.IsNullOrEmpty(dt_tmp.Rows[0]["SCALE" + (k + 1).ToString() + "TICKET"].ToString()) == true) { break; } dt1.Rows.Add(dr); } dt1.Columns["ps_scheduletype"].DefaultValue = "A"; dt1.Select("").ToList<DataRow>().ForEach(r => r["ps_scheduletype"] = dt_tmp.Rows[j]["schedule_type"].ToString()); dt1.Select("").ToList<DataRow>().ForEach(r => r["ps_scale"] = ps[n].ToString()); dt_ps.Merge(dt1); } } objmst.sqlbcopy(dt_ps, "temp_pricescale"); }