Quantcast
Channel: Coding Angel » Database
Viewing all articles
Browse latest Browse all 20

How to create dataset without using database in C#

$
0
0
  • This topic explains about how to create dataset without using database in C# programming.
  • Tools needed: RichTextBox1 (RichTextBox1).

What is Dataset?create dataset without using database in C#

  • Dataset represents a collection of data retrieved from the Data Source.  Usually it is represented in tabular form. The DataSet contains DataTableCollection and their DataRelationCollection. Dataset can read the data in XML file.

Namespace:  System.Data

Assembly:  System.Data (in System.Data.dll)

  • Syntax for DataSet class

// Declaration
[SerializableAttribute()]
public class DataSet : MarshalByValueComponent, IListSource {
}

DataTable Class create dataset without using database in C#

  • DataTable class represents one table of in-memory data.
  • Syntax

// Declaration
[SerializableAttribute()]
public class DataTable : MarshalByValueComponent, IListSource {
}

DataColumn Classcreate dataset without using database in C#

  • DataColumn Class represents the schema of a column in a DataTable.
  • Syntax

// Declaration
public class DataColumn : MarshalByValueComponent {
}

DataColumn Constructor (String, Type)create dataset without using database in C#

  • It inititalizes a new instance of the DataColumn class that used in specified column name and data type.
  • Syntax

// Declaration
    public DummyClass(string columnName, Type dataType) {
    }

  • String – Column name
  • Type – Data type

How to create dataset without using database in C#Complete Code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            DataTable dt;
            DataRow dr;
            DataColumn idCoulumn;
            DataColumn nameCoulumn;
            int i;
            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);
            // adding datarow to datatable
            dr = dt.NewRow();
            dr["ID"] = "1";
            dr["Name"] = "Rahul";
            dt.Rows.Add(dr);
            dr = dt.NewRow();
            dr["ID"] = "2";
            dr["Name"] = "Manu";
            dt.Rows.Add(dr);
            dr = dt.NewRow();
            dr["ID"] = "3";
            dr["Name"] = "Ravi";
            dt.Rows.Add(dr);
            // adding datatable to dataset
            ds.Tables.Add(dt);
            for (i = 0; (i
                        <= (ds.Tables[0].Rows.Count - 1)); i++)
            {
                RichTextBox1.Text = (RichTextBox1.Text
                            + (ds.Tables[0].Rows[i][0] + ("   --   " + ds.Tables[0].Rows[i][1])));
                RichTextBox1.Text = (RichTextBox1.Text + "\r\n");
            }
        }

    }
}

 

C# Files and Directory C# WORD
C# Path Class How to insert picture in Excel using C#
Save the image to system from PictureBox in C# How to insert Picture as Background image in Excel using C#
Read text file and write text file in C# Create Excel Chart in C# PictureBox
How to append file using C# Export Excel chart to Picture file using C#
How to read file in C# Draw chart in Excel using C# programming
Create and write file using C# Create an Excel file from XML file using C#
Different file operation in C# Save the image to system from PictureBox in C#
Count files in Directory using C# Working of Font Dialog in C#
BinaryWriter in C# Working of SaveFileDialog Component in C#
BinaryReader in C# Make ctrl A to select all text in C#
  How to create numeric TextBox in C#
  How to spell check in C#
  Working of Color Dialog in C#

How to create dataset without using database in C#


Viewing all articles
Browse latest Browse all 20

Latest Images

Trending Articles





Latest Images