Several Methods for Traversing datatable [reprinted]

Source: Internet
Author: User
Able Traversal method Method 1: datatable dt = dataset. tables [0]; for (INT I = 0; I <DT. rows. count; I ++) {string strname = DT. rows [I] ["field name"]. tostring ();} Method 2: foreach (datarow myrow in mydataset. tables ["Temp"]. rows) {var STR = myrow [0]. tostring ();} method 3: foeach (datarow DR in DT. rows) {object value = Dr ["columnsname"];} Method 4: able dt = new datatable (); foreach (datarow DR in DT. rows) {(INT I = 0; I <DT. Columns. Count; I ++) {Dr [I] ;}} binds the datatable to reapter. If (dtb_xx.rows.count> 0) {rp_xx.datasource = dtb_xx; rp_xx.databind () ;}< ASP: repeater id = "rp_xx" runat = "server"> <itemtemplate> <tr> <TD> <div> <ul class = "listhorizontally"> <li> <Div class =" tcell1 "> <% # eval (" ID ") %> </div> </LI> <li> <Div class = "tcell2"> <% # eval ("name ") %> </div> </LI> </ul> </div> </TD> </tr> </itemtemplate> </ASP: repeater> Method 5 datarow [] datarows = NULL; datarows = able. sel ECT (fieldparentid + "= '" + treenode. tag. tostring () + "'", datatable. defaultview. sort); foreach (datarow in datarows) {datarow = datatable. rows [I];? = Datarow [fieldparentid]. tostring ();}

 

Several Methods for Traversing datatable [reprinted]

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.