Disconnected Mode in ADO.NET using C# with Example

disconnected-Mode
Disconnected-Mode

C# Disconnected Mode in ADO.NET with Example

In Disconnected Mode in ADO.NET using C# architecture, there is no need to open connection to access data from database and no need to make connection alive while we perform insert, update, delete and search operation and after retrieve data from database no need connection close.

In Disconnected Mode ADO.NET, DataAdapter is used as a Dataprovider that provides communication between DataSet and database . This can be done using fill method to fill Data into DataSet and after modification in dataset data, We use DataAdapter update method to update data into Database. In Disconnected Mode in ADO.NET, DataSet can hold multiple table data.So DataSet is also called as virtual Database Because in connected mode when you constantly trips to the database for any (I U D S operation) insert, update, delete and search operation you wish to do. This creates more traffic to the database. So the limitation of Connected Mode ADO.NET is removed under Disconnected Mode in Ado.Net.

Example:-
Create a Table in Database having following fields as in screenshot:
Disconnected-Mode-Table
Disconnected-Mode-App-sc

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication1
{
    public partial class Disconnected_Mode : Form
    {
        public Disconnected_Mode()
        {
            InitializeComponent();
        }
// Save button coding to Save data into Database Table.
        private void btnsave_Click(object sender, EventArgs e)
        {
            SqlConnection con=new SqlConnection(@”Data Source=MALIKMALIK;Initial Catalog=smalik;Integrated Security=True”);
            SqlDataAdapter da = new SqlDataAdapter(“Select * from tb_test”, con);
//Coding to Fill Data into Dataset using DataAdapter
                     DataSetds = new DataSet();
            da.Fill(ds);
//Coding to Save Data into Dataset
            DataTable dt = ds.Tables[0];
            DataRow dr = dt.NewRow();
            dr[0] = txtrollno.Text;
            dr[1] = txtfirstname.Text;
            dr[2] = txtlastname.Text;
            dt.Rows.Add(dr);
//Coding to Save or Update DataSet Data into Database using DataAdapter.
            SqlCommandBuilder scb = new SqlCommandBuilder(da);
            da.Update(ds);
            MessageBox.Show(“Data Saved”);
        
           
          
        }
// Search button coding to Search data From Database Table.
        private void btnsearch_Click(object sender, EventArgs e)
        {
            SqlConnection con=new SqlConnection(@”Data Source=MALIKMALIK;Initial Catalog=smalik;Integrated Security=True”);
            SqlDataAdapter da = new SqlDataAdapter(“Select * from tb_test”, con);
//Coding to Fill Data into Dataset using DataAdapter
            DataSet ds = new DataSet();
            da.Fill(ds);
//Coding to Search Data From Dataset.
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                if (dr.RowState.ToString() != “Deleted”)
                    if (dr[0].ToString() == txtrollno.Text)
                    {
                        txtfirstname.Text = dr[1].ToString();
                        txtlastname.Text = dr[2].ToString();
                        break;
                    }
            }
        }
// Delete button coding to delete data From Database Table.
        private void btndelete_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(@”Data Source=MALIKMALIK;Initial Catalog=smalik;Integrated Security=True”);
            SqlDataAdapter da = new SqlDataAdapter(“Select * from tb_test”, con);
//Coding to Fill Data into Dataset using DataAdapter
            DataSet ds = new DataSet();
            da.Fill(ds);
//Coding to Delete Data From Dataset.
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                if (dr.RowState.ToString() != “Deleted”)
                    if (txtrollno.Text == dr[0].ToString())
                    {
                        dr.Delete();
                        MessageBox.Show(“Data Deleted from DataSet”);
                        break;
                    }
            }
//Coding to Save all non-deleted DataSet Data into Database using DataAdapter.
            SqlCommandBuilder scb = new SqlCommandBuilder(da);
            da.Update(ds);
            MessageBox.Show(“Data Deleted from Database”);
        }
// Update button coding to update modified data into Database Table.
        private void btnupdate_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(@”Data Source=MALIKMALIK;Initial Catalog=smalik;Integrated Security=True”);
            SqlDataAdapter da = new SqlDataAdapter(“Select * from tb_test”, con);
//Coding to Fill Data into Dataset using DataAdapter
            DataSet ds = new DataSet();
            da.Fill(ds);
//Coding to Save modified Data into Dataset.
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                if (txtrollno.Text == dr[0].ToString())
                {
                    dr[1] = txtfirstname.Text;
                    dr[2] = txtlastname.Text;
                 MessageBox.Show(“Data Update in DataSet”);
                 break;
                            
                }
            }
//Disconnected Mode in Ado.Net using C# Coding to Save Updated or Modified DataSet Data into Database using DataAdapter.
            SqlCommandBuilder scb = new SqlCommandBuilder(da);
            da.Update(ds);
            MessageBox.Show(“Data Update in Database”);
        }
    }
}

//End of Disconnected Mode in Ado.Net using C# Coding with Example.

Download Keygen

Download Serial Key

Popular Downloads:

Download Advanced System Optimizer
Download Activation Key

Download Apowersoft Screen Recorder Pro 2.1
Download Activation Key

Download Ashampoo Photo Commander 14.0.4
Download Activation Key

Download EaseUS Data Recovery Wizard 9.9.0
Download Activation Key

Download Movavi Video Suite 15.2
Download Activation Key

Download Adguard Latest
Download Activation Key

Download IObit Malware Fighter Pro 3.4.0.12
Download Activation Key

Download Eset Nod32 Antivirus
Download Activation Key

Download Avast Internet Security Latest
Download Activation Key

Download AVG Internet Security Latest
Download Activation Key

Download HideMyIP Premium
Download Activation Key

Comments

  1. Richard Smith says:

    Everything work perfect, thank you.

  2. Karen Ratte says:

    Worth every penny. It has saved my bacon several times and easy to use, reliable and quick. Support is fantastic too.

  3. ERDAL says:

    Good stuff here, it is the best by far

  4. Mark C. says:

    This is a good source and many will find it very helpful.

  5. JennyC says:

    Thank you this extremely helpful! It’s seriously like find a gold mine. Thanks!

  6. Emily says:

    This is absolutely awesome! and the free version is cover most needed for just backup + upload to cloud storages. I really love it!

Leave a Comment

Your email address will not be published. Required fields are marked *