ADO.Net - DataSet() - DotNet and DataBase

Wednesday, 1 August 2018

ADO.Net - DataSet()



A dataset is the collection of data tables. We can add one or more data tables in the dataset and can access directly by table name of its address in the dataset using disconnected architecture/distributed data scenarios
We can fill a DataSet from an XML stream or document. We can use the XML stream or document to supply to the DataSet either data, schema information, or both. 

LINQ on DataSet

LINQ to DataSet provides language-integrated querying capabilities for disconnected data stored in a DataSet. LINQ to DataSet uses standard LINQ syntax and provides compile-time syntax checking, static typing, and IntelliSense support when we are using the Visual Studio IDE.

DataSet few Properties
Properties
Description
CaseSensitive
To check whether DataTable objects are case-sensitive or not.
DataSetName
To get or set the name of the current DataSet.
DefaultViewManager
To get a custom view of the data contained in the DataSet to allow filtering and searching.
HasErrors
To check whether there are errors in any of the DataTable objects within this DataSet.
IsInitialized
To check whether the DataSet is initialized or not.
Locale
To get or set the locale information used to compare strings within the table.
Namespace
To get or set the namespace of the DataSet.
Tables
To get the collection of tables contained in the DataSet.


DataSet few Methods:


Method
Description
BeginInit()
To begin the initialization of a DataSet that is used on a form.
Clear()
To clear the DataSet of any data by removing all rows in all tables.
Clone()
To copy the structure of the DataSet.
Copy()
To copy both the structure and data for this DataSet.
Merge(DataSet)
To merge a specified DataSet and its schema into the current DataSet.
Merge(DataTable)
To merge a specified DataTable and its schema into the current DataSet.
Reset()
To clear all tables and removes all relations, foreign constraints, and tables from the DataSet.

Example


using System;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
namespace EmployeeTimeSheet
{
    public partial class InsertEmployees : Form
    {
        public InsertEmployees()
        {
            InitializeComponent();
        }

        private void btnInsert_Click(object sender, EventArgs e)
        {
            string connection = ConfigurationManager.ConnectionStrings["connection"].ConnectionString;
            SqlConnection con = new SqlConnection(connection);
            con.Open();
            SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM EmployeeInfo", con);
            DataSet ds = new DataSet();
            da.Fill(ds, "Employees");
            dgvEmployees.DataSource = ds.Tables["Employees"];
            con.Close();


        }
}

No comments:

Post a Comment

x

Get Updates On

Discussion updates

Straight Into Your INBOX!

Enter your email address to subscribe to this website and receive notifications of new posts by email.