- Method One:
- DataTable Tbldatas = new DataTable ("Datas");
- DataColumn DC = null;
- DC = TBLDATAS.COLUMNS.ADD ("ID", Type.GetType ("System.Int32"));
- dc. AutoIncrement = true; Automatically add
- dc. AutoIncrementSeed = 1; //starting at 1
- dc. AutoIncrementStep = 1; //step 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"] = "Fight Dedicated";
- TBLDATAS.ROWS.ADD (NewRow);
- NewRow = Tbldatas.newrow ();
- newrow["Product" = "Folding stool";
- newrow["Version"] = "3.0";
- newrow["Description"] = "One of the seven arms of a walking lake";
- 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 # inserting data into a DataTable or falsifying a DataTable