ADO.Net questions Flashcards
What is ADO .NET ?
-ADO.NET is the abbreviation for ActiveX Data Object. It is a part of the .NET Framework by Microsoft that provides a set of classes that can be used to handle data interaction with data sources such as databases
- We can use ADO.NET to connect to these data sources and retrieve, handle, and update the data that is stored.
-Sai Krishna C
What are the provider objects present in ADO. Net Framework
- Sai Krishna C
A .NET Framework data provider is used for connecting to a database, executing commands, and retrieving results. Those results are either processed directly, placed in a DataSet in order to be used.
-Connection: Establishes a connection to a specific data source.
-Command: Executes a command against a data source.
-DataReader: Reads a forward-only, read-only stream of data from a data source.
-DataAdapter: Populates a DataSet and resolves updates with the data source.
How can you define the Dataset structure?
- Bhargav Bhat
In ADO.NET, a dataset is an in-memory representation of data that is retrieved from a database or other data source. It consists of a collection of Datatable objects that contain the actual data, as well as information about the structure of the data, such as column names and data types.
We need to define the Dataset structure to ensure the integrity and accuracy of the data that is stored and manipulated in the Dataset. By defining the schema, we can enforce constraints on the data, ensure that the relationships between the tables are correct, and make it easier to retrieve and manipulate the data in a consistent and reliable way.
- Bhargav Bhat
What are the methods of DataSet?
- Bhargav Bhat
It is used in disconnected architecture. It represents records in the form of a Database table format. It stores records of one or more tables.
Methods of DataSet:
AcceptChanges(): This method saves changes that are made with records in a Dataset.
Clear(): This method clears all rows from Dataset.
Clone(): The clone method copies the structure of Dataset. This means it copies only schema not full records of DataSet.
Copy(): It copies the whole records with the structure of DataSet.
RejectChanges(): This method discards changes which are made with DataSet and set the DataSet to the previous stage (which was at first).
HasChanges(): This method returns a boolean value to show whether the record of the Dataset has changed or not. It returns true if any changes have been made and false if no other changes made.
GetChanges(): This method keeps a copy of those record, which is changed or modified.
- Bhargav Bhat
What are the architectures followed by Ado.net?
_Aman Shankar
The architecture followed by Ado.net for the connectivity with the database is categorized into two modes:-
- Connected Architecture
As the name suggests, connected architecture refers to the fact that the connection is established for the full time between the database and application. - Disconnected Architecture
Disconnected architecture refers to the mode of architecture in Ado.net where the connectivity between the database and application is not maintained for the full time. There is no need to establish a connection for the full-time because DataSet acts as temporary storage.
Difference between Connected and Disconnected architecture.
_Aman Shankar
Connected Architecture
- It is connection-oriented.
- In this, we mainly use the object of the DataReader class.
- Connected methods give a faster performance.
- Connected can hold the data of a single table.
- Connected architecture is forward-only and read-only.
- Data Reader can’t persist the data.
- It is Read-only, we can’t update the data.
Disconnected Architecture
- It is disconnection oriented.
- In this, we mainly use the object of the SqlDataAdapter and DataSet classes.
- Disconnected gets low in speed and performance.
- Disconnected can hold multiple tables of data.
- The dataset can persist the data
- We can update the data
what and why we use Data Adapter?
-Siva Billudu
Data Adapter will acts as a Bridge between Data Set and database. This data Adapter object is used to read the data from database and bind that data to dataset. Data Adapter is a disconnected oriented architecture.
Data Adapter is a part of the ADO.NET Data Provider. Data Adapter provides the communication between the Dataset and the database. We can use the Data Adapter in combination with the Data Set Object. Data Adapter provides this combination by mapping Fill method, which changes the data in the Data Set to match the data in the database and Update, which changes the data in the database to match the data in the Data Set.
The Data Adapter can perform Select , Insert , Update and Delete SQL operations in the Data Source.
syntax:
SqlDataAdapter sda = new SqlDataAdapter(string query,connection string);
What are the several execution methods of ADO.NET?
-syed sohail
Following are the execute methods of a ADO.NET command object:
Execute Scalar: This method returns a single value from the result get from the execution of SQL query.
For example like : MAX,MIN,AVERAGE,COUNT.
Execute Non Query: This method execute the DML SQL query like insert, update, delete and returns the number of rows affected.
Execute Reader: This method helps us to read the data when we execute the select command and stores it in a data reader object which is a forward-only result set.
What is Connection Pooling in ADO.NET? - Cibi Sharan
Connection Pooling is a technique where a database connection is reused instead of creating a new connection every time an operation is performed. This can reduce overhead involved and improve performance.
To enable connection pooling in ADO.NET, you can set the Pooling attribute to true in the connection string. By default, connection pooling is enabled in ADO.NET.
Eg: string connectionString = “Data Source=serverName;Initial Catalog=databaseName;User ID=userName;Password=password;Pooling=True;”;
What and Why we use Data Reader?
–Siva Billudu
Data Reader is used to read the data from the database and it is a stream-based,read only and forward only connection oriented architecture during fetch the data from database.
The Data Reader cannot be created directly from code, they can created only by calling the Execute Reader method of a Command Object.A Connection Object can contain only one Data Reader at a time and the connection in the Data Reader remains open.
syntax:
SqlDataReader r=sqlcmd.ExecuteReader();
DataReader.read();
The Read() method in the Data Reader is used to read the rows from Data Reader and it always moves forward to a new valid row, if any row exist .Data Reader will fetch the data very fast when compared with dataset.
what are the steps for disconnected architecture in ADO.NET ?
-syed sohail
- create sql connection object and pass connection string as parameter .
2.open the connection
3.create the adapter object and pass the query to be executed and the connection object
4.create the dataset object
5.fill the data adapter result in to the dataset
6.we can perform any data manipulation operations on the dataset
What are some Connection Pooling attributes?
- Cibi Sharan
Some of the connection pooling attributes are :
- Connection Lifetime - Length of time after which a connection is destroyed. By default, it is 0, which is maximum.
- Connection Reset - Specifies whether connection is reset when removed from pooling. Default is true.
- Max Pool Size - Maximum number of connections allowed in pool. Default is 100.
- Min Pool Size - Minimum number of connections allowed in pool. Default is 0.
- Pooling - If true, connection is taken from the appropriate pool. By default, true.
Cibi Sharan
what are some of the important namespaces available in ADO.NET?
-Mounika B
There are some important namespaces available in ADO.NET are:
=>All data-related classes reside in the
System. Data namespace which can be found in the System.Data.dll assembly and it’s secondary namespaces are:
*. System.Data.SqlClient (SQL Server)
*. System.Data.OledbClient (Excel, MS access)
*. System.Data.OracledbClient (oracle)
*. System.Data.PostgresClient (postgres)
*. Microsoft.Data.Odbc : This can be used to connect a Microsoft Access database to an external data source such as Microsoft SQL Server
*. System.Data.Common: This allows you to Map the table names and columns names in the Data Set Using DataColumnMapping and DataTableMapping classes.
*.System.Data.SqlTypes: It provides the Data types with the same semantics and precision as the data types in SQL Server database.
What is the use of Transaction in ADO.NET?
-Mounika B
Transaction in ADO.NET is used when you want to bind multiple tasks together so that they execute as a single unit of work
=>ADO.NET supports single-database transactions as well as distributed transactions.
=>Single-database transaction model is implemented using the underlying .NET managed providers for Transaction and Connection classes from the System.Data namespace.
=>Distributed transaction model is implemented using classes in the namespace System.Transactions.
What is the Use of Transaction?
=>To keep the data consistent while we access the data using ADO.NET.
=>Ensures that all operations within the work unit are completed successfully
EX:
public class Transaction
{
static void Main(string[] args)
{
string Connectionstring = (connection string);
SqlConnection con = new
SqlConnection(Connectionstring);
con.Open();
SqlTransaction transaction= con.BeginTransaction();
try
{
SqlCommand cmd1 = new SqlCommand(“select * from student”, con, transaction);
cmd1.ExecuteNonQuery();
SqlCommand cmd2 = new SqlCommand(“select * from student”,con,transaction);
cmd2.ExecuteNonQuery();
transaction.Commit();
}
catch (Exception ex) {
transaction.Rollback();
Console.WriteLine(“Transaction failed”,ex.Message);
}
}
}
What is data binding in ADO.NET?
-Yugaraj
Data binding in ADO.NET is the process through which user interface (UI) controls of a client application are configured to update or fetch data from data sources like a database or XML document. Using data binding, the user will be able to bind values to the particular control.
Simple data binding: It is the process of binding the control with only one value in the dataset.
Complex data binding: It is the method of binding the component with the Database. The controls can be a Dropdown list, GridView, or combo box.