DataTable dt=new DataTable ("cart");
DataColumn dc1=new DataColumn ("Prizename", Type.GetType ("System.String"));
DataColumn dc2=new DataColumn ("point", Type.GetType ("system.int16"));
DataColumn dc3=new DataColumn ("number", Type.GetType ("system.int16"));
DataColumn dc4=new DataColumn ("Totalpoint", Type.GetType ("System.Int64"));
DataColumn dc5=new DataColumn ("Prizeid", Type.GetType ("System.String"));
Dt. Columns.Add (DC1);
Dt. Columns.Add (DC2);
Dt. Columns.Add (DC3);
Dt. Columns.Add (DC4);
Dt. Columns.Add (DC5);
The above code completes the schema of the DataTable, but there is no data in it
for (int i=0;i<10;i++)
{
DataRow Dr=dt. NewRow ();
dr["Prizename"]= "Doll";
dr["Point"]=10;
dr["Number"]=1;
dr["Totalpoint"]=10;
dr["Prizeid"]= "001";
Dt. Rows.Add (DR);
}
10 identical records are filled in.
Somebody's going to do this.
DataRow dr=new DataRow ();
..
Dt. Rows.Add (DR);
This is not possible, because a DataRow must belong to a DataTable, can not be built out of thin air, like a record must belong to a table like
Someone else did it again.
DataRow Dr=dt. NewRow ();
dr["Prizename"]= "Doll";
dr["Point"]=10;
dr["Number"]=1;
dr["Totalpoint"]=10;
dr["Prizeid"]= "001";
for (int i=0;i<10;i++)
{
Dt. Rows.Add (DR);
}
This is also wrong, because the DataTable already has this DataRow, just like there is no 2 records in a table, must each newrow ()
C # directly creates a DataTable and adds data to it (custom DataTable) to