Join Our Email Alerts-Subscribe
Important Note:Login & Check Your Email Inbox and Activate Confirmation Link

Enter Your Email :

Copyright Disclaimer:
Section 107 of the Copyright Act Fair Use Contents .
We are forwarding content link(s) from our website to content website & We are not serving any contents.
Main the Content PDF link(s) is/are obtained from GoogleSearch
for the purpose of Education & Teaching Intention. Not for commercial purpose. is not liable/responsible for any copyright issues.

ADO.Net Materials-Free Download

What do you understand by SqlTransaction class in ADO.NET?

Answer: The SqlTransaction class is an important class of .NET Framework. It ensures that a body of code will affect a Database or kept the same as previous (Rollback).

At first we should know about it's two most important method which will be used here. They are given below.

• Commit(): It commits the transaction. It save changes made in Database during transaction. In simple term we can also say that it shows the end of transaction at that time.

• Rollback(): It is used to rollback the transaction. It set the database in previous stage which was, before the begin of transaction.

What are the two fundamental objects in ADO.NET?

Answer: There are the two fundamental objects in ADO.NET:

• Data reader

• Data set

DataReader Class:

The DataReader class object allows you to read the data returned by a SELECT command by a simple forward-only and read-only cursor. It requires a live connection with the data source and provides a very efficient way of looping and consuming all parts of the result set. The object of the DataReader cannot be directly instantiated. Instead you must call the ExecuteReader method of the Command object and close the connection when you are done using the DataReader otherwise the connection remains alive until it is explicitly closed.

DataReader with ExecuteReader() Method:

1. //Open connection

2. Conn.Open();

3. sdr = sc.ExecuteReader(CommandBehavior.CloseConnection);

4. //Get all records

5. while(sdr.Read())

6. {

7. textBox1.AppendText(sdr.GetValue(0) + "\t" + sdr.GetValue(1));

8. textBox1.AppendText("\n");

9. }

DataSet class:

A DataSet is a disconnected architecture technology. It contains zero or more tables and relationships. When you work with a dataset, the data in the data source is not touched at all. Instead all the changes are made locally to the dataset in memory. In the following example you will see how to retrieve data from a SQL Server table and use it to fill in a DataTable object in the DataSet.


1. private void Form1_Load(object sender, EventArgs e)

2. {

3. //Connection String

4. string conString = "Data Source=localhost;Database=AdventureWorksLT2008;Integrated Security=SSPI";

5. // Add Connection string to SqlConnection

6. SqlConnection Conn = new SqlConnection(conString);

7. string query = "select * from SalesLT.Customer";

8. //Command Class definition

9. SqlCommand sc = new SqlCommand(query, Conn);

10. // Data Adapter definition

11. SqlDataAdapter sda = new SqlDataAdapter();

12. sda.SelectCommand = sc;

13. //data Set definition

14. DataSet ds = new DataSet();

15. // filling the result set in data table

16. sda.Fill(ds, "SalesLT.Customer");

17. //output in data grid

18. dataGridView1.DataSource = ds.Tables["SalesLT.Customer"];

19. }

What is DataAdapter and its property?

Answer: A DataAdapter bridges the gap between the disconnected DataTable objects and the physical data source. The SqlDataAdapter is capable of executing a SELECT, DELETE and UPDATE statement on a data source as well as extracting input from the result set into a DataTable object. The SqlDataAdapter class provides a method called Fill() to copy the result set into the DataTable.

Which namespaces are used for data access?

Answer: ADO.NET is a collection of managed libraries used by .NET applications for data source communication using a driver or provider.

ADO.NET provides libraries for the datasource communication under the following namespaces.

1. system.Data

2. system.Data.OleDb

3. system.Data.SqlClient

4. system.Data.OracleClient

5. system.Data.Odbc

1. System.Data: This namespace is used for holding and managing data on a client machine.

2. System.Data.OleDb: This namespace can communicate with any data source like files, databases, indexing servers and so on using the “OleDb” Provider.

3. System.Data.SqlClient: This namespace can communicate with “SQL Server” database only using SqlClient Providers.

4. System.Data.OracleClient: This namespace can communicate with an “Oracle” database only using OracleClient Providers.

5. System.Data.ODBC: This namespace contains the same set of classes as the following:

o Connection

o Command

o DataReader

o DataAdaptar

o CommandBuilder

o Parameter

Explain the properties and methods of Command Object.

Answer: The command object is one of the basic components of ADO .NET.

1. The Command Object uses the connection object to execute SQL queries.

2. The queries can be in the form of Inline text, Stored Procedures or direct Table access.

3. An important feature of Command object is that it can be used to execute queries and Stored Procedures with Parameters.

4. If a select query is issued, the result set it returns is usually stored in either a DataSet or a DataReader object.

Explain the ExecuteReader method:

1. The DataReader object is a forward-only and read-only cursor.

2. It requires a live connection to the data source.

3. The DataReader object cannot be directly instantiated. Instead, we must call the ExecuteReader() method of the command object to obtain a valid DataReader object.


1. SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

Explain the ExecuteScalar method in ADO.NET?


The ExecuteScalar Method in SqlCommandObject returns the first column of the first row after executing the query against the Data Source.

1. If the result set contain more than one column or rows, it takes only the first column of the first row. All other values are ignored.

2. If the result set is empty it will return null.


1. Int32 TotalSalary = Convert.ToInt32(cmd.ExecuteScalar());

Question 31: Explain the ExecuteXmlReader?

Answer: The execute reader method is flexible when we need the result set in the form of an XML doucment. The ExecuteXmlReader methods returns an instance of XmlReader class.

Example: XmlReader xmlreader = cmd.ExecuteXmlReader();

XmlDocument xdoc = new XmlDocument();

Using the XmlDocument class we load the XmlReader object and save it to the File System using the Save method.

What is clone() method of DataSet?

Answer: The clone method copy the structure of DataSet. Means it copy only schema not full records of DataSet.

Take another DataGridView and one button in your project and write the following code on button click event.

1. private void btnclone_Click(object sender, EventArgs e)

2. {

3. DataSet daset = ds.Clone();

4. dataGridView2.DataSource = daset.Tables[0];

5. }

Now run the application.


Click the "Clone" button. The following figure shows that only structure has copied.

Question 36: What is the Copy() method of DataSet?

Answer: Copy the whole records with structure of DataSet.

Take a button and set it's text as copy and write the following code on click event.

1. private void btncopy_Click(object sender, EventArgs e)

2. {

3. DataSet daset = ds.Copy();

4. dataGridView2.DataSource = daset.Tables[0];

5. }

Now run the application.

What is the preferred method for executing SQL commands that contain parameters?

Answer: The preferred method is to use the SqlParameter and oleDbParameter objects, as detailed in the section "Using Parameters with the command Object."

The SqlParameter class is found in the "System.Data.SqlClient" namespace. It is a class of a connected architecture of .NET framework. It represents parameters. To work with the SqlParameter class we should have a database.

Hpw DataSet objects in ADO.NET replace the ADO Recordset object?

Answer : DataSet is good for ADO.NET objects to replace the ADO Recordset object:

• DataSet can hold multiple tables at a time.

• It allows data access to easily read or write data operations in / from the database.

• DataSet data stores in local system.

• It holds multiple rows at a time.

• It uses more memory.

• DataSet maintain relation.

• It bind data from the database.

DataSet representation in .aspx.cs code,

1. protected void BindDataSet()

2. {

3. SqlConnection con = new SqlConnection("your database connection string ");

4. con.Open();

5. SqlCommand cmd = new SqlCommand("Write your query or procedure ", con);

6. SqlDataAdapter da = new SqlDataAdapter(cmd);

7. DataSet ds = new DataSet();

8. da.Fill(ds);

9. grid.DataSource = ds;

10. grid.DataBind();

11. }

What is Transactions and Concurrency in ADO.NET?

Answer: Transactions: ADO.NET providers a transaction class that represents a transaction. All data providers provide their own version of the transaction class. The IDbTransaction interface implements the basic functionality of the transaction class. All data provider-specific classes implement this namespace.

Source: Contents are provided by Technicalsymposium Google Group Members. Disclaimer: All the above contents are provided by Google Group members. Further, this content is not intended to be used for commercial purpose. is not liable/responsible for any copyright issues.

Free Technical Interview Materials PDF

Placement Papers & Answers PDF-Download

Fresher Jobs & Off-Campus Interview Details

Government Jobs

All State and Central Government Jobs/Railway & Bank Jobs/Alll Competitive Exams-Complete Details.

Software Jobs

Entry Level Software & IT Jobs in Chennai/Bangalore & Leading Metro Cities-Complete Details.


All Software Companies & Core Companies Off-Campus Interviews & Walk-in across India-Complete Details.

Free Aptitude Materials PDF-Download Study Materials PDF-Download All Study Notes PDF Live Support-Chat with Our Experts

Official Contact: +91-9245556793 (Whatsapp Message / SMS / Voice Call)

Our Expert team is ready to answer all your questions immediately-Feel free to speak in Tamil/English.

(Example:Events info/Lecture Notes/Off-Campus & All Jobs/Projects & All education information)

Working hrs (IST): (Morning: 10:00AM-3:00 PM) and (Evening:5:00 PM to 10:00 PM)

All Latest Question & Answer Page (FAQ)-Click here