How to modify datarow itemarray value with example code




The below example give a clear explanation on How to modify a datarow in C#.


          SqlConnection con = new SqlConnection(connectionstring);
            string query = "Select * from App_Branch";
            con.Open();
            SqlCommand cmd = new SqlCommand(query, con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet DS = new DataSet();
            da.Fill(DS);

            DataTable dt = new DataTable();
            foreach (DataRow item in DS.Tables[0].Rows)
            {
                if (item.ItemArray[2].ToString().Equals("0"))
                {
                    item["ColumnName"] = "Somthing";
//you can not give like this  item.ItemArray[4] = "Somthing";
                }
                else
                {
                    item["ColumnName"] = "Somthing";
                }
                dt.Rows.Add(item.ItemArray);

            }





No comments:

Post a Comment