When to bind dataview?

Source: Internet
Author: User
When binding controls, I think dataset is very convenient, but why is there dataview? It is easier to use dataview to operate offline databases. The following Article It also explains how to use dataview to update back to Dataset:
Purpose:

When using the data view, you can obtain filtered or sorted records from the data view (instead of directly obtaining records from the table where the data is located) to access these records.When certain restrictions are observedYou can also update, insert, and delete records through the data view:

    • The data view must contain sufficient information about each record to determine the position of the record in the data table. This information can contain a primary key or other columns (these columns together provide sufficient information to uniquely identify records, such as customer names, addresses, and cities ).
    • For each operation , And Attribute must be setTrue.

Search records
Search for records in the Data View
SetSortSet the attribute to one or more columns you want to search.
Call the Data ViewFind or findrowsThe value to be searched in the sorted column.
If you want to find a single record, call the find method.
-Or-
If you want to find multiple records, use the findrows method.
Dataview1.sort = "customerid ";
Int foundindex = dataview1.find (textbox1.text );
Note: To use the find method, use sort first.

Read records
Read records from the Data View
UseIndexThe value points to the record to be accessed in the data view.
You can access the column by name reference column in the data view, as shown in the following example. It gets the customer name of the first record in the View:

Dataview dataview1 =   New Dataview (Ds. MERs mers );
String Cname = Dataview1 [ 0 ] [ " Customername " ]. Tostring ();

 

Update record
Update records through data view
InCode, Use the index value to identify the record to be updated, and then reference the column name to set the column value.
Note: If the allowedit attribute of the data view is set to false, records cannot be edited through the data view.
The following example shows how to identify and update a column.

 

Dataview1 [ 0 ] [ " CompanyName " ] =   " Fabrikam, Inc. " ;

Insert record
Insert records in the Data View
Call the addnew Method of Data View to create a new record and return a datarowview object:

 


Datarowview DRV;
DRV = Dataview1.addnew ();

Note: Unlike dataset operations
Update a record like any data view record.
Note: If the allownew attribute of the data view is set to false, records cannot be inserted through the data view.
The following example shows how to add a new record to the view and update three fields:

 

// C #
Datarowview DRV;
DRV = Dataview1.addnew ();
DRV [ " Customerid " ] =   " Aaa " ;
DRV [ " CompanyName " ] =   " Aafabrikam, Inc. " ;
DRV [ " City " ] =   " Aurora " ;

Delete record
Delete records from the Data View
Call the delete method of the Data View to pass the index of the record to be deleted:
Note: If the allowdelete attribute of the data view is set to false, records cannot be deleted from the data view.
The following example shows how to delete a record:

 

// C #
Dataview1.delete ( 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.