DataTable data modification, column change

Source: Internet
Author: User

Add ColumnsDataTable table= New DataTable (); Table.            Columns.Add ("ID", typeof (int)); Table. Columns.Add ("LName", typeof (String));Delete Columntable. Columns.remove ("Name");Modify column namesDt. columns["Num"].  ColumnName = "Search Volume"; Add row DataRow dr = Datatable.newrow (); dr["columnName1"] = value1;dr["columnName2"]= "value2";d r["columnName3"] = "Value3";d ataTable.Rows.Add (DR);
A DataTable is made up of DataRow rows.
Get line Fourth: DataRow dremployee = dtemployees.rows[3];
The DataRow class provides 3 methods for suspending and recovering the state of a data row when editing data: BeginEdit, EndEdit, and CancelEdit methods. When editing data, calling BeginEdit can suspend any event (or exception), use the Items collection to specify the column name and new value of the data to be modified, and re-recover any events (or exceptions) with EndEdit Using CancelEdit, you can roll back any changes and reactivate any event or exception.
Dremployee.beginedit ();  
Dremployee ("empname") = "John";
Dremployee ("Title") = "Sales";
Traverse: foreach (DataRow item in DT. Rows)
Verify: if (item["item"] is DBNull | |! Stringutil.hastext (item["tag"]) continue; item["Tag"] is a data in each row.
(DBNull indicates that the database has no related data, stringutil.hastext only when null, "", "" is false
Modifying a sequence
Move column named "Money" to column 5th
datatable.columns["Money"]. SETORDINAL[4];

DataTable data modification, column change

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.