CSharp.Net-Informations.com
   Home      .Net Framework      VB.NET      C#                                                                      About


  How to Dyanamic Dataset in C#

The DataSet Object represents a complete set of data, including related tables, constraints, and relationships among the tables . The DataSet contains DataTableCollection and their DataRelationCollection . The DataTableCollection contains zero or more DataTable objects.

ADO.NET enables you to create DataTable objects and add them to an existing DataSet. A DataTable is defined in the System.Data namespace and represents a single table of memory-resident data. You can set constraint information for a DataTable by using the PrimaryKey and Unique properties. The following C# Source Code shows how to fill a DataTable without using a DataSource .

         C# Source Code Download           Print Source Code
         How to Dyanamic Dataset in C# - Download
        
C# Tutorial

using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            DataTable dt ;
            DataRow dr ;
            DataColumn idCoulumn ;
            DataColumn nameCoulumn ;
            int i = 0;

            dt = new DataTable();
            idCoulumn = new DataColumn("ID", Type.GetType("System.Int32"));
            nameCoulumn = new DataColumn("Name", Type.GetType("System.String"));

            dt.Columns.Add(idCoulumn);
            dt.Columns.Add(nameCoulumn);

            dr = dt.NewRow();
            dr["ID"] = 1;
            dr["Name"] = "Name1";
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr["ID"] = 2;
            dr["Name"] = "Name2";
            dt.Rows.Add(dr);

            ds.Tables.Add(dt);

            for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
            {
                MessageBox.Show(ds.Tables[0].Rows[i].ItemArray[0] + " -- " + ds.Tables[0].Rows[i].ItemArray[1]);
            } 

        }
    }
}



CSharp Dataset Related Contents
*     What is C# ADO.NET Dataset
*     C# Datset with Sql Server Data Provider
*     C# Datset with OLEDB Data Provider
*     Find Tables in a Dataset - Sql Server
*     Find Tables in a Dataset - OLEDB
*     How to Dataset rows count - Sql Server
*     How to Dataset rows count - OLEDB
*     How to find Column Definition SqlServer
*     How to find Column Definition OLEDB
*     C# Dataset with multiple tables - Sql Server
*     C# Dataset with multiple tables - OLEDB
*     C# Dataset table relations
*     C# Dataset merge tables - Sql Server
*     C# Dataset merge tables - OLEDB


   Home      VB.NET      C#
CSharp Related Topics
*     An overview of Microsoft CSharp
*     C# Language Tutorial
*     C# Statements Tutorial
*     C# Collection Tutorial
*     C# String Tutorial
*     C# File Operations Tutorial
*     C# Excel Tutorial
*     C# Crystal Reports Tutorial
*     CSharp Communication Tutorial
*     C# Ado.Net Tutorial and Source Code
*     C# ADO.NET data Providers Tutorial
*     C# Dataset Tutorial
*     C# DataAdapater Tutorial
*     Csharp DataView Tutorial
*     Csharp Remoting Tutorial
*     C# XML Tutorial
*     C# DataGridView Tutorial
   Home      VB.NET      C#
More Source Code :   
Mail to :  feedback@net-informations.com
  |  Home   |  VB.NET   |  C#   |  SiteMap   |  Terms of Use   |  About   |
net-informations.com (C) 2010
All Rights Reserved. All other trademarks are property of their respective owners.