SoFunction
Updated on 2025-03-07

C# programming method to implement DataTable to add rows

This article describes the C# programming method to add rows in DataTable. Share it for your reference, as follows:

Method 1:

DataTable tblDatas = new DataTable("Datas");
DataColumn dc = null;
dc = ("ID", ("System.Int32"));
 = true;//Automatically increase = 1;//The beginning is 1 = 1;//The step size is 1 = false;//
dc = ("Product", (""));
dc = ("Version", (""));
dc = ("Description", (""));
DataRow newRow;
newRow = ();
newRow["Product"] = "Fruit Knife";
newRow["Version"] = "2.0";
newRow["Description"] = "Fighting Special";
(newRow);
newRow = ();
newRow["Product"] = "Folding Stool";
newRow["Version"] = "3.0";
newRow["Description"] = "One of the seven weapons of walking in the world";
(newRow);

Method 2:

DataTable tblDatas = new DataTable("Datas");
("ID", ("System.Int32"));
[0].AutoIncrement = true;
[0].AutoIncrementSeed = 1;
[0].AutoIncrementStep = 1;
("Product", (""));
("Version", (""));
("Description", (""));
(new object[]{null,"a","b","c"});
(new object[] { null, "a", "b", "c" });
(new object[] { null, "a", "b", "c" });
(new object[] { null, "a", "b", "c" });
(new object[] { null, "a", "b", "c" });

I hope this article will be helpful to everyone's C# programming.