{"id":84760,"date":"2023-03-21T08:09:04","date_gmt":"2023-03-21T07:09:04","guid":{"rendered":"https:\/\/drafts.code-maze.com\/?p=84760"},"modified":"2023-03-21T08:09:04","modified_gmt":"2023-03-21T07:09:04","slug":"csharp-datatable-class","status":"publish","type":"post","link":"https:\/\/code-maze.com\/csharp-datatable-class\/","title":{"rendered":"DataTable Class in C#"},"content":{"rendered":"<p>In this article, we are going to cover the DataTable class in C#.<\/p>\n<div style=\"padding: 20px; border-left: 5px #dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To download the source code for this article, you can visit our <a href=\"https:\/\/github.com\/CodeMazeBlog\/CodeMazeGuides\/tree\/main\/csharp-intermediate-topics\/DataTableOverview\" target=\"_blank\" rel=\"nofollow noopener\">GitHub repository<\/a>.<\/div>\n<p><code>DataTable<\/code> is a data structure that is a member of the <code>System.Data<\/code> namespace. It consists of columns that define the data type and rows that hold individual records, making it ideal for structured data sets. Good use cases include reading information from a relational database or files organized in columns and rows.<\/p>\n<h2><a id=\"create-data-table\"><\/a> Create a DataTable and Define the Structure<\/h2>\n<p>Creating a\u00a0<code>DataTable<\/code> in C# requires two steps:<\/p>\n<ul>\n<li>Declaring and instantiating a <code>DataTable<\/code> object<\/li>\n<li>Defining the structure by calling the <code>Add()<\/code> method on the\u00a0<code>Columns<\/code> property<\/li>\n<\/ul>\n<p>Let&#8217;s jump in with an example.<\/p>\n<p>First, let&#8217;s declare and instantiate <code>dt<\/code>, a <code>DataTable<\/code>:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var dt = new DataTable();<\/code><\/p>\n<p>Next, let&#8217;s define the structure of our table:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">dt.Columns.Add(\"Ticker\", typeof(string));\r\ndt.Columns.Add(\"Date\", typeof(DateTime));\r\ndt.Columns.Add(\"Price\", typeof(double));<\/pre>\n<p>Calling the <code>Add()<\/code> method creates a new <code>DataColumn<\/code> object and assigns a reference to it in the <code>Columns<\/code> property of <code>dt<\/code>, our <code>DataTable<\/code>.\u00a0 Passing <code>Ticker<\/code>, <code>Date<\/code> and <code>Price<\/code> as <code>string<\/code> parameters defines the <code>ColumnName<\/code> property of the new columns. We use the <code>typeof<\/code>operator to explicitly define the <code>DataType<\/code> property of our <code>DataColumn<\/code> objects.<\/p>\n<h2><a id=\"populate-data-table\"><\/a> Populate a DataTable in C#<\/h2>\n<p>Now that we&#8217;ve created and defined our <code>DataTable<\/code>, let&#8217;s add some data. There are three steps to adding a record:<\/p>\n<ul>\n<li>Declaring and instantiating a <code>DataRow<\/code> object by calling the <code>NewRow()<\/code> method on the <code>DataTable<\/code><\/li>\n<li>Populating the <code>DataRow<\/code> by setting each column to the data we want to populate<\/li>\n<li>Calling the <code>Add()<\/code> method on the <code>Rows<\/code> property to add the new <code>DataRow<\/code> to our <code>DataTable<\/code><\/li>\n<\/ul>\n<p>Let&#8217;s apply these steps by adding a record for Microsoft&#8217;s stock price.<\/p>\n<p>First, let&#8217;s create a <code>DataRow<\/code> object:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">DataRow row = dt.NewRow();<\/code><\/p>\n<p>Next, let&#8217;s update <code>row<\/code> by referencing each column to insert the data we want to add:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">row[\"Ticker\"] = \"MSFT\";\r\nrow[\"Date\"] = new DateTime(2023, 3, 3);\r\nrow[\"Price\"] = 255.29;<\/pre>\n<p>Here, we use the <code>ColumnName<\/code> property of each <code>DataColumn<\/code> object to populate the data. However, we could\u00a0populate the columns by index:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">row[0] = \"MSFT\";\r\nrow[1] = new DateTime(2023, 3, 3);\r\nrow[2] = 255.29;<\/pre>\n<p>The <code>Ordinal<\/code> property of the <code>DataColumn<\/code> object assigns a zero-based <code>int<\/code> index to each column in the order it&#8217;s added. Referencing <code>0<\/code>, <code>1<\/code> and <code>2<\/code> has identical behavior to referencing <code>Ticker<\/code>, <code>Date<\/code> and <code>Price<\/code>. We&#8217;re just referencing different properties of the same object.<\/p>\n<h2><a id=\"data-table-props\"><\/a> Common DataTable Properties<\/h2>\n<p>In addition to the <code>Columns<\/code> and <code>Rows<\/code> properties, <code>DataTable<\/code> has a couple of common properties that allow us to apply relational data modeling concepts in memory in C#.<\/p>\n<h3><a id=\"primary-key\"><\/a> Primary Key<\/h3>\n<p>A primary key is defining one or more columns as a unique identifier for records in a table. We can use the <code>PrimaryKey<\/code> property to define this in C# with a <code>DataColumn[]<\/code> <code>object<\/code>.<\/p>\n<p>Building off our example, let&#8217;s create a new column and assign it as the primary key of our table:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var pkCol = new DataColumn(\"Key\", typeof(int));\r\ndt.Columns.Add(pkCol);\r\n\r\nvar pkCols = new DataColumn[1];\r\npkCols[0] = pkCol;\r\n\r\ndt.PrimaryKey = pkCols;<\/pre>\n<p>First, we&#8217;re defining <code>pkCol<\/code>, a variable referencing <code>Key<\/code>, a new <code>DataColumn<\/code> we&#8217;re adding to our table. Next, we create <code>pkCols<\/code>, which is holding a reference to <code>Key<\/code>, the column we want as our primary key. Finally, we&#8217;re setting the <code>PrimaryKey<\/code> property to the <code>pkCols<\/code> column array, defining the primary key of our table.<\/p>\n<h3><a id=\"constraints\"><\/a> Constraints<\/h3>\n<p>Constraints allow us to set rules to limit what can be inserted into a table. This is beneficial as it guarantees reliability in tables and relationships between multiple tables. In C#, the <code>Constraints<\/code> property references a <code>ConstraintsCollection<\/code> object that stores defined constraints.<\/p>\n<p>Let&#8217;s look at what constraints exist on our table:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">foreach (Constraint constraint in dt.Constraints)\r\n{\r\n    Console.WriteLine(constraint.ConstraintName);\r\n    Console.WriteLine(constraint.GetType());\r\n}<\/pre>\n<p>Here, we loop through each item in our table&#8217;s <code>ConstraintCollection<\/code> and print the <code>ConstraintName<\/code> and <code>type<\/code>.<\/p>\n<p>Let&#8217;s run the code and view the output:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">Constraint1\r\nSystem.Data.UniqueConstraint<\/pre>\n<p><code>Constraint1<\/code> is our only <code>Constraint<\/code> object in our <code>Constraints<\/code> property. It is a <code>UniqueConstraint<\/code> that was automatically created by defining the <code>PrimaryKey<\/code> property for our table. It prevents adding duplicates to our <code>Key<\/code> column, ensuring integrity for the unique identifier of our table.<\/p>\n<h2><a id=\"data-table-methods\"><\/a> Common Methods of DataTable Class in C#<\/h2>\n<p><code>DataTable<\/code> has several common methods that make wrangling structured data sets easy.<\/p>\n<h3><a id=\"clone\"><\/a> Clone<\/h3>\n<p>The <code>Clone()<\/code> method takes a copy of the schema and columns but does not copy any of the actual data.<\/p>\n<p>Let&#8217;s clone\u00a0<code>dt<\/code> as an example:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">DataTable dtClone = dt.Clone();<\/code><\/p>\n<p>Next, let&#8217;s print out the columns. First, we&#8217;ll create a helper method to do this:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static void PrintColumns(DataTable dt)\r\n{\r\n    foreach (DataColumn col in dt.Columns)\r\n        Console.WriteLine(col.ColumnName);\r\n}<\/pre>\n<p>Then, we&#8217;ll call it on our cloned table:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">PrintColumns(dtClone);<\/code><\/p>\n<p>The output shows the identical column structure:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">Date\r\nPrice\r\nKey<\/pre>\n<h3><a id=\"copy\"><\/a> Copy<\/h3>\n<p>The <code>Copy()<\/code> method copies a table&#8217;s underlying structure and the actual content of the table.<\/p>\n<p>Let&#8217;s try it on\u00a0<code>dt<\/code>. First, we&#8217;ll create a helper method to print out the content of a\u00a0<code>DataTable<\/code> object:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static void PrintData(DataTable dt)\r\n{\r\n    foreach (DataRow row in dt.Rows)\r\n    {\r\n        foreach(DataColumn col in dt.Columns)\r\n        {\r\n            Console.WriteLine($\"{col}: {row[col]}\");\r\n        }\r\n    }\r\n}<\/pre>\n<p>Next, we&#8217;ll copy our table, and print out the contents:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">DataTable dtCopy = dt.Copy();\r\nPrintData(dtCopy);<\/pre>\n<p>The output shows identical data to what we&#8217;ve added in <code>dt<\/code>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">Ticker: MSFT\r\nDate: 3\/3\/2023 12:00:00 AM\r\nPrice: 255.29\r\nKey: 0<\/pre>\n<h3><a id=\"select\"><\/a> Select<\/h3>\n<p>The <code>Select()<\/code> method allows us to easily access data rows. We can pass a <code>string<\/code> argument with an expression to filter records. Let&#8217;s say we add an additional record to <code>dt<\/code>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-highlight=\"6\">row = dt.NewRow();\r\n\r\nrow[\"Ticker\"] = \"AMZN\";\r\nrow[\"Date\"] = new DateTime(2023, 3, 6);\r\nrow[\"Price\"] = 93.75;\r\nrow[\"Key\"] = 1;\r\n\r\ndt.Rows.Add(row);<\/pre>\n<p>Now, let&#8217;s access our new record. We can do this by writing an expression that filters the table by the <code>Ticker<\/code>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">string expression = \"Ticker='AMZN'\";\r\nDataRow[] result = dt.Select(expression);<\/pre>\n<p>Next, let&#8217;s write a helper method to print out the results:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static void PrintSelectedRows(DataRow[] rows, DataTable dt)\r\n{\r\n    foreach (DataRow dr in rows)\r\n    {\r\n        foreach (DataColumn col in dt.Columns)\r\n        {\r\n            Console.WriteLine($\"{col}: {dr[col]}\");\r\n        }\r\n    }\r\n}<\/pre>\n<p>Finally, we can call this method to view the output of our <code>Select()<\/code> method call:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">PrintSelectedRows(result, dt);<\/code><\/p>\n<p>Which prints out the expected result of the <code>DataRow<\/code> objects that have a <code>Ticker<\/code> value of AMZN:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">Ticker: AMZN\r\nDate: 3\/6\/2023 12:00:00 AM\r\nPrice: 93.75\r\nKey: 1<\/pre>\n<h2><a id=\"practical-example-datatable\"><\/a> Practical Example With DataTable Class in C#<\/h2>\n<p>Let&#8217;s take everything we&#8217;ve learned and apply it to an example. A common scenario is <a href=\"https:\/\/code-maze.com\/csharp-read-data-from-csv-file\/\" target=\"_blank\" rel=\"noopener\">loading data into a program<\/a> from a <code>.csv<\/code> file. A <code>.csv<\/code> file is structured so columns are separated by a comma, and rows are separated by a new line.<\/p>\n<p>First, let&#8217;s create a method to load a file into a <code>DataTable<\/code>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static DataTable CsvToDataTable(string filePath)\r\n{\r\n    var dtRes = new DataTable();\r\n    using (var parser = new TextFieldParser(filePath))\r\n    {\r\n        parser.TextFieldType = FieldType.Delimited;\r\n        parser.TrimWhiteSpace = true;\r\n        parser.SetDelimiters(\",\");\r\n\r\n        var columns = parser.ReadFields();\r\n\r\n        foreach (var col in columns)\r\n            dtRes.Columns.Add(col);\r\n\r\n        while (!parser.EndOfData)\r\n        {\r\n            var row = parser.ReadFields();\r\n            dtRes.LoadDataRow(row, true);\r\n        }\r\n    }\r\n    return dtRes;\r\n}<\/pre>\n<p>Here, we use <code>parser<\/code>, a <code>TextFieldParser<\/code> object that has built-in methods for reading structured text files to read a <code>.csv<\/code> file. We then use the <code>LoadDataRow()<\/code> method to read content from a <code>.csv<\/code> into <code>dtRes<\/code>, the <code>DataTable<\/code> that is returned with the file contents.<\/p>\n<p>Next, let&#8217;s write a method to load the <code>.csv<\/code> <code>veggie-sales<\/code> into our program:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static void ProcessSales()\r\n{\r\n    var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, \"vegetable-sales.csv\");\r\n    DataTable veggieSales = CsvToDataTable(filePath);\r\n}<\/pre>\n<p>Now that we&#8217;ve loaded the file into a table, let&#8217;s apply a filter to analyze sales for carrots:<\/p>\n<p><code><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">DataRow[] carrotSales = veggieSales.Select(\"Vegetable='Carrot'\");<\/code><\/code><\/p>\n<p>Finally, we can view the output using our <code>PrintSelectedRows()<\/code> method from our previous example:<\/p>\n<p><code><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">Program.PrintSelectedRows(carrotSales, veggieSales);<\/code><\/code><\/p>\n<p>Which prints out the records for carrot sales to the console:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">Vegetable: Carrot\r\nQuantity: 1\r\nPrice: 1\r\nSales: 1\r\nVegetable: Carrot\r\nQuantity: 1\r\nPrice: 3\r\nSales: 1<\/pre>\n<h2><a id=\"conclusion\"><\/a> Conclusion<\/h2>\n<p>DataTable class in C# is an excellent choice for storing and manipulating structured data sets. It has built-in methods to easily define columns and populate rows with data. Properties like <code>PrimaryKey<\/code> and <code>Constraints<\/code> enable the application of data modeling best practices. Methods like <code>Copy()<\/code>, <code>Clone()<\/code> and <code>Select()<\/code> allow easy data transformation in memory.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we are going to cover the DataTable class in C#. DataTable is a data structure that is a member of the System.Data namespace. It consists of columns that define the data type and rows that hold individual records, making it ideal for structured data sets. Good use cases include reading information from [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":62189,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[12],"tags":[1478,1703],"class_list":["post-84760","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-csharp","tag-datatable","tag-datatable-methods","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>DataTable Class in C# - Code Maze<\/title>\n<meta name=\"description\" content=\"In this article, we are going to learn about DataTable class in C#. We&#039;ll see how we can use it, and what methods and properties it containts\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/csharp-datatable-class\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"DataTable Class in C# - Code Maze\" \/>\n<meta property=\"og:description\" content=\"In this article, we are going to learn about DataTable class in C#. We&#039;ll see how we can use it, and what methods and properties it containts\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/csharp-datatable-class\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2023-03-21T07:09:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Code Maze\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Code Maze\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/csharp-datatable-class\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/csharp-datatable-class\/\"},\"author\":{\"name\":\"Code Maze\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\"},\"headline\":\"DataTable Class in C#\",\"datePublished\":\"2023-03-21T07:09:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-datatable-class\/\"},\"wordCount\":1000,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-datatable-class\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"keywords\":[\"DataTable\",\"DataTable Methods\"],\"articleSection\":[\"C#\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/csharp-datatable-class\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/csharp-datatable-class\/\",\"url\":\"https:\/\/code-maze.com\/csharp-datatable-class\/\",\"name\":\"DataTable Class in C# - Code Maze\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-datatable-class\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-datatable-class\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"datePublished\":\"2023-03-21T07:09:04+00:00\",\"description\":\"In this article, we are going to learn about DataTable class in C#. We'll see how we can use it, and what methods and properties it containts\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/csharp-datatable-class\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/csharp-datatable-class\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/csharp-datatable-class\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"width\":1100,\"height\":620,\"caption\":\"C# Development\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/csharp-datatable-class\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"DataTable Class in C#\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\",\"name\":\"Code Maze\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"caption\":\"Code Maze\"},\"description\":\"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/company\/codemaze\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog\"],\"url\":\"https:\/\/code-maze.com\/author\/codemazecontributor\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"DataTable Class in C# - Code Maze","description":"In this article, we are going to learn about DataTable class in C#. We'll see how we can use it, and what methods and properties it containts","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code-maze.com\/csharp-datatable-class\/","og_locale":"en_US","og_type":"article","og_title":"DataTable Class in C# - Code Maze","og_description":"In this article, we are going to learn about DataTable class in C#. We'll see how we can use it, and what methods and properties it containts","og_url":"https:\/\/code-maze.com\/csharp-datatable-class\/","og_site_name":"Code Maze","article_published_time":"2023-03-21T07:09:04+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","type":"image\/png"}],"author":"Code Maze","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Code Maze","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/csharp-datatable-class\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/csharp-datatable-class\/"},"author":{"name":"Code Maze","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04"},"headline":"DataTable Class in C#","datePublished":"2023-03-21T07:09:04+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/csharp-datatable-class\/"},"wordCount":1000,"commentCount":2,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/csharp-datatable-class\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","keywords":["DataTable","DataTable Methods"],"articleSection":["C#"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/csharp-datatable-class\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/csharp-datatable-class\/","url":"https:\/\/code-maze.com\/csharp-datatable-class\/","name":"DataTable Class in C# - Code Maze","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/csharp-datatable-class\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/csharp-datatable-class\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","datePublished":"2023-03-21T07:09:04+00:00","description":"In this article, we are going to learn about DataTable class in C#. We'll see how we can use it, and what methods and properties it containts","breadcrumb":{"@id":"https:\/\/code-maze.com\/csharp-datatable-class\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/csharp-datatable-class\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/csharp-datatable-class\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","width":1100,"height":620,"caption":"C# Development"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/csharp-datatable-class\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"DataTable Class in C#"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04","name":"Code Maze","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","caption":"Code Maze"},"description":"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.","sameAs":["https:\/\/www.linkedin.com\/company\/codemaze\/","https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog"],"url":"https:\/\/code-maze.com\/author\/codemazecontributor\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/84760","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=84760"}],"version-history":[{"count":4,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/84760\/revisions"}],"predecessor-version":[{"id":84765,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/84760\/revisions\/84765"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/62189"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=84760"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=84760"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=84760"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}