---
title: "Access Data  &Update using ADO .NET"  
description: "In this blog we will discuss how to Access data using ADO .NET and make changes to it.  Codingusing System;  using System.Collections.Generic;  using"  
author: "Shankar M"  
published: 2013-03-29  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/470/access-data-update-using-ado-dot-net  
category: "ado.net"  
tags: ["ado.net"]  
reading_time: 2 minutes  

---

# Access Data  &Update using ADO .NET

In this blog we will discuss how to [Access data](https://www.mindstick.com/forum/159853/how-to-access-data-using-entity-framework-in-asp-dot-net-mvc) using ADO .NET and make changes to it.\

##### Coding

```
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Data.SqlClient;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms; namespace UpdatingData{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }         private void Form1_Load(object sender, EventArgs e)        {             SqlConnection conn = new SqlConnection(               @"Data Source=yourServerName;user id=UserName;password=Password;" +               "Initial Catalog=DatabaseName");             SqlDataAdapter thisAdapter = new SqlDataAdapter(               "SELECT EMPNO,ENAME FROM EMP", conn);              SqlCommandBuilder thisBuilder = new SqlCommandBuilder(thisAdapter);              DataSet ds = new DataSet();              thisAdapter.Fill(ds, "Employee");               Console.WriteLine("name before change: {0}",               ds.Tables["Employee"].Rows[5]["ENAME"]);             ds.Tables["Employee"].Rows[5]["ENAME"] = "Johnson";             thisAdapter.Update(ds, "Employee");             Console.WriteLine("name after change: {0}",               ds.Tables["Employee"].Rows[5]["ENAME"]);          }    }}
```

Here,

```
   SqlConnection conn = new SqlConnection(    @"Data Source=yourServerName;user id=UserName;password=Password;" +  "Initial Catalog=DatabaseName");
```

The above block of code is SQL – Server specific [connection String](https://www.mindstick.com/articles/328/connection-strings) to the database

```
SqlDataAdapter thisAdapter = new SqlDataAdapter( "SELECT EMPNO,ENAME FROM EMP", conn);
```

Here we create a [DataAdapter](https://www.mindstick.com/blog/194/dataadapter-in-ado-dot-net) object to [Operations](https://www.mindstick.com/blog/304985/how-does-devops-bridge-the-gap-between-development-and-operations-teams-like-git) such as Update

[SqlCommandBuilder](https://www.mindstick.com/interview/33995/sqlcommandbuilder-in-ado-dot-net) thisBuilder = new SqlCommandBuilder(thisAdapter);

The SqlCommandBuilder is used to build SQL statements

DataSet ds = new DataSet();

##### Here, we create a DataSet object to hold data.

thisAdapter.Fill(ds, "Employee");

In the above statement we will the DataSet with the query we have previously defined for the DataAdapter.

Console.WriteLine("Name before change: {0}",ds.Tables["Employee"].Rows[5]["ENAME"]);

##### Displaying the data before change

ds.Tables["Employee"].Rows[5]["ENAME"] = "Johnson";

In the above line, we change the data in Employee table, row 5 with the [column name](https://www.mindstick.com/forum/369/how-can-i-add-a-column-name-to-my-grid) ENAME

thisAdapter.Update(ds, "Employee");

Here we make a call to the Update command to make the changes [permanent](https://answers.mindstick.com/qa/50600/what-is-a-permanent-storage-in-pc) to the [database Table](https://www.mindstick.com/forum/159366/how-to-test-regular-expressions-in-sql-without-using-database-table).

Console.WriteLine("Name after change: {0}",ds.Tables["Employee"].Rows[5]["ENAME"]);

Thanks for reading

---

Original Source: https://www.mindstick.com/blog/470/access-data-update-using-ado-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
