Some developer like to use DataSet to store the data, some like to use DataTable instead.
The different between this two is DataSet can have more than one DataTable, and DataTable cannot have multiple DataTable.
So from the capability we know that DataSet require more resources than DataTable.
Example below to create DataTable Dynamically.
1: DataTable TableName = new DataTable();
2: TableName.Columns.Add("ID", typeof(int));
3: TableName.Columns.Add("Name", typeof(string));
4: TableName.Columns.Add("Email", typeof(string));
5: TableName.Columns.Add("PhoneNo", typeof(string));
The Above code show how to create DataTable dynamically.
The above code is equivalent in SQL syntax below :
1: CREATE TABLE TableName
2: (
3: ID data_type(size),
4: Name data_type(size),
5: Email data_type(size),
6: PhoneNo data_type(size),
7: );
Add new row in DataTable
Below is example how to add new row data into DataTable.
1: DataRow row = TableName.NewRow();
2: row["ID"] = 1;
3: row["Name"] = "My Name";
4: row["Email"] = "My Email";
5: row["PhoneNo"] = "My Phone No";
6: TableName.Rows.Add(row);
The above code equivalence with sql syntax below :
1: INSERT INTO TableName VALUES (1,"My Name","My Email","My PhoneNo");
0 comments:
Post a Comment