Asp.net detailed description of the DataTable operation (add search for deletion and modification)

Source: Internet
Author: User

The primary key of the data table uses id column auto-increment. For example, the table structure: users table

Id Name Sex Add Tel
All data in the users table is retrieved to a able dataset through the dataset and sqldataadapter. Query: datatable dt = database tutorial query set; datarow [] dr = dt. select ("id =" + txt_id.value); txt_name.value = dr [0] ["name"]. tostring (); txt_add.value = dr [0] ["add"]. tostring (); add: datatable = database query set; datatable. rows. add (new object [] {name, sex, add, tel}); Data list binding (datatable); Delete: datatable dtable = database query set; dtable. rows. remove (dtable. select ("id = 2") [0]); Data list binding (datatable); changed: datatable dtable = database query set; datarow drow = dtable . Select ("id = 3") [0]; drow. beginedit (); drow ["name"] = txt_name.value.trim (); drow ["add"] = txt_add.value.trim (); drow. endedit (); Data list binding (dtable); Note: select (...) appears multiple times in this article (..........) [0]; why is this code followed by [0]? Because the select query returns a datarow [] set, we only need the first element in the set. The following table is 0.

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.