During the meeting, master said that during data center reconstruction, we should try not to use datatable as the return value. Instead, we should use the generic set method to implement real object orientation. The problem was solved by checking the information and communicating with the students. I have some knowledge about generic collections.
I. Understanding of generic Sets
1. It exists in the namespace of system. Collection and generic.
2. gener
=== Premise: we already have a datatable data table. All we need now is a row of Data ===
For example, the following sectionCodeIn a method, a datatable is returned!
Sqlcon
=
New
Sqlconnection (strcon );Sqlcom
=
New
Sqlcommand ();Sqlcom. Connection
=
Sqlcon;Sqlcom. commandtext
=
"
Select_v
"
;Sqlcom. commandtype
=
Commandtype. storedprocedure;Sqlcon. open ();SD
When using a strongly typed generic dataset, the following steps are generally used to improve the performance of your application if you want to include the expression column in the DataTable.
1. First use the DataAdapter.Fill method to populate a DataTable.
2. Then add the expression column to the DataTable by encoding.
3. Bind the
to return the primary key columns for a DataTable, displayed in a DataGrid. The second example demonstrates to set the primary key columns for a DataTable.
[Visual Basic]
Private Sub Getprimarykeys (myTable as DataTable)
' Create the array for the columns.
Dim Colarr () as DataColumn
Colarr = Mytable.primarykey
' Get the # of elements in the array.
Console.Writ
The datatable. Select method returns an array of all datarow objects. Select () has four overload methods.
Name
Description
Select ()
Obtains the array of all datarow objects.
Select (string)
Obtain the array of all datarow objects that match the filtering conditions according to the primary key order (if no primary key exists, the addition order is followed.
Select (string, string)
Obta
Datatable filters datarow that meets the criteria
Datatable filters row. In. Net framework3.5 and 4.0, it is relatively easy to use because of the existence of LINQ. In framework2.0, it is a little clumsy, but it is also very useful. Is to use the datatable. Select () method, the specific definition is as follows:Public datarow [] Select (string filtere
I. Introduction
Binding repeater to datareader is a common and efficient form of data binding. Sometimes you can use the data source control (datasource) of ASP. net2.0, but it does not feel flexible enough.In general, repeater and datareader can be directly bound:
Sqldatareader Dr
=
New
Sqlutility. executereader (...);Repeater. datasource
=
Dr;Repeater. databind ();
However, sometimes, when repeater data is bound for secondary classification, dropdownlist must also be bound to t
Some special usage of datatable: select
/**/
/** In addition, dataview can be used for retrieval.*/
Datatable datasource
=
New
Datatable ();Dataview dv
=
Datasource. defaultview;DV. rowfilter
=
"
Columna = 'abc'
"
;
//
1. Obtain the datatable directly after filtering
Binary serializationIn remote systems, data structures of the collection type are often required to be transmitted. datatable and ilist
Define a test class
Using system;
Using system. Collections. Generic;
Using system. text;
Using system. Data;
Namespace wintest
{
[Serializable]
Public class testclass
{
Public testclass ()
{
// The data volume per unit is as follows
Col1 = "234124323 for normal attachment with dish ";
Col2 = "234 for normal attachme
1. First quote DocumentFormat.OpenXml.dll2. Then create a new Openexcelhelper class to convert Excel to a DataTable. Organize a DataTable according to the specified Excel streampublic static DataTable Getexceldata (string sheetname, String stream){using (spreadsheetdocument document = Spreadsheetdocument.open (stream, false)){Open Excelienumerableif (sheets. Coun
1. Execute datatable.select ("conditions") in the DataTable to return to the DataTable;Executing a query in a DataTable returns a new DataTableDT is the source data DataTableCondition is a query conditionDataTable NEWDT = new DataTable ();NEWDT = dt. Clone (); Cloning DT structure, including all DT architectures and co
When writing code in the morning, a problem occurs. Use able. Select ("filter condition") to filter data and then pay it to another datatable. An error occurred while running the result. The error message is as follows:Databinding: "system. Data. datarowview" does not contain the attribute "cityname.
Error Code
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->Public class virtualdata
{
Public virtuald
9-non-connection mode of ADO. NET, DataSet in memory, DataTable --- ShinePans,
DataSet is called a DataSet. It can be compared to a database in memory. DataSet is ADO. NET core, supports ADO.. NET disconnected. The core object of the distributed data solution is also the core component for non-connection-based data query.
Common attributes of DataTable:
Attribute
Description
Columns
Sample I:
I created a public method called linqtodatatable as following:
Public datatable linqtodatatable {Datatable dtreturn = new datatable ();// Column namesPropertyinfo [] oprops = NULL;
If (varlist = NULL) return dtreturn;
foreach (t rec in varlist) { will follow If (oprops = NULL) { foreach (propertyinfo PI in oprops) {
If (coltype. isgenerictype)
private int getcount () {datatable dt /// known datadable, with tens of thousands of records datatable newdt = DT. defaultview. totable ( true , " city " ); int num = newdt. rows. count; return num ;}
datatable sourcetable = New soursetable (); sourcetable. columns. add ( " Code " , string ); /// ... add data to soursetable datav
Code
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> /// /// Returns the datatable after the select distinct operation. /// /// Source data table /// Field set /// Private Datatable selectdistinct (datatable sourcetable, Params String [] Fieldnames){ Object [
Datatable converts the data into Json and puts the Json data into the js file. datatablejson
5 code instances in C # converting Datatable to Json
///
// Query the province name var SQL = "select top 35 locid, locname, parentid from location where loctype = 1"; var dt_pro = SQLHelper. get_DataTable (SQL, SQLHelper. getCon (), new Dictionary
For example, enter var cn_pro = [{"locid": 1, "locname": "Be
Generics listFirst we have to take out the DataTable in the dataset, the dataset belongs to the DataTable collection, through the index or tablename can take out the DataTable, the DataTable has more than one column is the table in the database field, To map the attribute variables in the entity class, we assign values
Example of Self-deletion (drTemp is a table and gvSummary is dev's gridview. Right-click grid to delete ):
1. dtTemp. Rows. RemoveAt (gvSummary. FocusedRowHandle );
2. dtTemp. Rows [gvSummary. FocusedRowHandle]. Delete (); dtTemp. AcceptChanges ();
In C #, if you want to delete a row in the DataTable, there are several methods:
1. if you only want to delete a row in the datatable, you can use the delete Sta
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.