Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to modify a Datatable

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 166
    Comment on it

    Steps to modify data in a DataTable

    Suppose we have a DataTable with columns Name,Age, Status

      //DataTable dtRecords;
          DataRow[] rows = dtRecords.Select();
              if (rows != null && rows.Length > 0)
              {
                  foreach (DataRow row in rows)
                  {
                      if (Convert.ToInt16(row["Age"]) > 18 )
                      {
                          row["Status"] = "Can Vote";
                     }
                  }
              }
     

    OR
    you can also select specific rows then work accordingly

                  string name = "xxx";
                  DataRow[] rows = dtRecords.Select("Name = " + name);
                if (rows != null && rows.Length > 0)
                {
                    foreach (DataRow row in rows)
                    {
                        lblName.Text = Convert.ToString(row["Name"]);
                    }
                }                                 

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: