C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
ADO.NET DataTableDataTable represents relational data into tabular form. ADO.NET provides a DataTable class to create and use data table independently. It can also be used with DataSet also. Initially, when we create DataTable, it does not have table schema. We can create table schema by adding columns and constraints to the table. After defining table schema, we can add rows to the table. We must include System.Data namespace before creating DataTable. DataTable Class Signaturepublic class DataTable : System.ComponentModel.MarshalByValueComponent, System.ComponentModel.IListSource, System.ComponentModel.ISupportInitializeNotification, System.Runtime.Serialization.ISerializable, System.Xml.Serialization.IXmlSerializable DataTable ConstructorsThe following table contains the DataTable class constructors.
DataTable PropertiesThe following table contains the DataTable class properties.
DataTable MethodsThe following table contains the DataTable class methods.
DataTable ExampleHere, in the following example, we are creating a data table that populates data to the browser. This example contains the following files. // DataTableForm.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DataTableForm.aspx.cs" Inherits="DataTableDemo.DataTableForm" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> </div> <asp:GridView ID="GridView1" runat="server"> </asp:GridView> </form> </body> </html> CodeBehind// DataTableForm.aspx.cs using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace DataTableDemo { public partial class DataTableForm : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { DataTable table = new DataTable(); table.Columns.Add("ID"); table.Columns.Add("Name"); table.Columns.Add("Email"); table.Rows.Add("101", "Rameez","rameez@example.com"); table.Rows.Add("102", "Sam Nicolus", "sam@example.com"); table.Rows.Add("103", "Subramanium", "subramanium@example.com"); table.Rows.Add("104", "Ankur Kumar", "ankur@example.com"); GridView1.DataSource = table; GridView1.DataBind(); } } } Output: C# Public Access Specifier Exampleusing System; namespace AccessSpecifiers { class PublicTest { public string name = "Santosh Singh"; public void Msg(string msg) { Console.WriteLine("Hello "+ msg); } } class Program { static void Main(string[] args) { PublicTest publicTest = new PublicTest(); // Accessing public variable Console.WriteLine("Hello "+publicTest.name); // Accessing public method publicTest.Msg("Peter Dicosta"); } } } Output: Hello Santosh Singh Hello Peter Dicosta
Next TopicADO.NET Web Form Example
|