SqlDataAdapter adp2 = new SqlDataAdapter("select source, destination, vehicle, rate from pickupdroptariff order by source", conn); DataTable dt2 = new DataTable(); adp2.Fill(dt2); dt2.Columns.Add("Rate_New"); int veh_rate=0; if (dt2.Rows.Count > 0) { for (int j = 0; j < dt2.Rows.Count; j++) { if(dt2.Rows[j][2].ToString()=="Small Car") { veh_rate = Convert.ToInt32(dt2.Rows[j][3].ToString()); veh_rate = veh_rate + small; //DataRow row = null; //row[4] = veh_rate.ToString(); //dt2.Rows.Add(row); dt2.Rows.Add("small",veh_rate.ToString()); } if(dt2.Rows[j][2].ToString()=="Regular Car") { veh_rate = Convert.ToInt32(dt2.Rows[j][3].ToString()); veh_rate = veh_rate + regular; dt2.Rows.Add("Regular", veh_rate.ToString()); } if(dt2.Rows[j][2].ToString()=="Luxury Car") { veh_rate = Convert.ToInt32(dt2.Rows[j][3].ToString()); veh_rate = veh_rate + luxury; dt2.Rows.Add("Luxury", veh_rate.ToString()); } } } GridView1.DataSource = dt2; GridView1.DataBind();
dt2
veh_rate