=== 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 ();
SDR = Sqlcom. executereader ();
DT = New Datatable ( );
DT. Load (SDR );
Assume that the returned datatable is DT,
Method 1: Copy A able, clear the data (the column structure is retained), and add the required row from DT using the importrow () method;
Datatable dt2 = new datatable ();
Dt2 = DT. Copy ();
Dt2.rows. Clear ();
Dt2.importrow (Dt. Rows [0]); // This is the first line added
Method 2:
First, the new able must be added to the corresponding column name (column)
An empty and non-structured able cannot directly add a row to it!
For ( Int I = 0 ; I < DT. Columns. Count; I ++ )
{
Dt2.columns. Add (Dt. Columns [I]. columnname); // you can add the column data type to the overload method.
}
Then you can join the row directly!
// 1
Datarow drq = Dt2.newrow ();
Drq. itemarray = DT. Rows [ 0 ]. Itemarray; // This is the first line added
Dt2.rows. Add (drq );
// 2
Dt2.importrow (Dt. Rows [ 0 ]); // This is the first line added
Finally, you can put the new able into Dataset:
DS = new dataset ();
DS. Tables. Add (dt2 );
A simple method to filter repeated rows of a rows table
Dataview View=Table. defaultview;
Datatable tagettable=View. totable (True,"Column1","Column2",...);