Home>

method one:

datatable tbldatas=new datatable ("datas");
datacolumn dc=null;
dc=tbldatas.columns.add ("id", type.gettype ("system.int32"));
dc.autoincrement=true;//Automatic increase
dc.autoincrementseed=1;//starts at 1
dc.autoincrementstep=1;//step size is 1
dc.allowdbnull=false;//
dc=tbldatas.columns.add ("product", type.gettype ("system.string"));
dc=tbldatas.columns.add ("version", type.gettype ("system.string"));
dc=tbldatas.columns.add ("description", type.gettype ("system.string"));
datarow newrow;
newrow=tbldatas.newrow ();
newrow ["product"]="fruit knife";
newrow ["version"]="2.0";
newrow ["description"]="For fighting only";
tbldatas.rows.add (newrow);
newrow=tbldatas.newrow ();
newrow ["product"]="Folding stool";
newrow ["version"]="3.0";
newrow ["description"]="One of the seven weapons of walking rivers and lakes";
tbldatas.rows.add (newrow);

Method Two:

datatable tbldatas=new datatable ("datas");
tbldatas.columns.add ("id", type.gettype ("system.int32"));
tbldatas.columns [0] .autoincrement=true;
tbldatas.columns [0] .autoincrementseed=1;
tbldatas.columns [0] .autoincrementstep=1;
tbldatas.columns.add ("product", type.gettype ("system.string"));
tbldatas.columns.add ("version", type.gettype ("system.string"));
tbldatas.columns.add ("description", type.gettype ("system.string"));
tbldatas.rows.add (new object [] {null, "a", "b", "c"});
tbldatas.rows.add (new object [] {null, "a", "b", "c"});
tbldatas.rows.add (new object [] {null, "a", "b", "c"});
tbldatas.rows.add (new object [] {null, "a", "b", "c"});
tbldatas.rows.add (new object [] {null, "a", "b", "c"});
c
  • Previous Learn with me the basic types and reference types of javascript
  • Next C # programming implementation of object and JSON string conversion example analysis