In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to understand ADO. NET data table". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the idea of Xiaobian slowly and deeply to study and learn "how to understand ADO. NET data table" together!
ADO. NET contains a ColumnsCollection that represents the schema of the table. A data table also contains a RowsCollection that represents the data that the table holds. It remembers the initial state as well as the current state and keeps track of changes that have occurred. To use a data table, users must include System.Data.
Creating ADO. NET Data Tables
DataTable has two constructors: public DataTable() public DataTable(string tableName)
Add Columns to ADO. NET Data Tables
DataTable contains a collection of DataColumn objects. This collection of columns defines the structure of the table. To add a new column to the collection, use the Add method of the collection. In the following example, we add three columns to a data table using the Add method of the ColumnsCollection class; this method specifies the ColumnName and DataType attributes.
DataColumn dc = null; DataTable dt = new DataTable("test"); dc = dt.Columns.Add("CustID",System.Type.GetType("System.Int32") ); dc = dt.Columns.Add("CustomerNameLast", System.Type.GetType("System.String") ); dc = dt.Columns.Add("CustomerNameFirst", System.Type.GetType("System.String") ); dc = dt.Columns.Add("Purchases", System.Type.GetType("System.Double") );
The Add method of ColumnsCollection on DataTable has two overloaded functions:
Public DataColumn Add(String columnname, Type type) Public DataColumn Add(String columnname)
expression column
ADO. NET also allows users to create and define expression columns. Expressions in ADO+ are used to filter, calculate, and summarize column information. To create an expression column, set the DataType property to the type appropriate for the value returned by the expression; then set the Expression property to a valid expression:
DataColumn dc = New DataColumn; dc.DataType = System.Type.GetType("System.Currency"); dc.Expression = "total * .086";
You can also use the Add method to create an expression column. For example, the code below adds a column that calculates a discount based on 10% of the customer purchase amount. This expression multiplies the column named Purchases by 10%.
DataColumn dc = New DataColumn; dc= dt.Columns.Add("rectg", System.Type.GetType("System.Double"), "total * 0.1");
When the table is populated, the column values will be 10% of the total column values.
autoincrement column
Another feature of DataColumn is its ability to act as an autoincrement column. AutoIncrement Columns Automatically increments the values in a new column when you add it. To create an AutoIncrement column, you need to set the AutoIncrement property of the column to true. Once this property is set, the column begins with the value defined in the AutoIncrementSeed property of the column. When a column is added, the value of the AutoIncrement column is incremented by the value in the AutoIncrementStep property of that column.
dc = dt.Columns.Add("CustID",System.Type.GetType("System.Int32") ); dc.AutoIncrement = true; dc. AutoIncrementSeed = 1; dc.AutoIncrementStep = 1; Thank you for reading, the above is "how to understand ADO. NET data table" content, after the study of this article, I believe we have a deeper understanding of how to understand ADO. NET data table this problem, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.