Important Note:Login & Check Your Email Inbox and Activate Confirmation Link
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 Source:Google.com.All the Content PDF link(s) is/are obtained from GoogleSearch
for the purpose of Education & Teaching Intention. Not for commercial purpose.
Technicalsymposium.com 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
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
3. sdr = sc.ExecuteReader(CommandBehavior.CloseConnection);
4. //Get all records
7. textBox1.AppendText(sdr.GetValue(0) + "\t" + sdr.GetValue(1));
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)
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"];
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: 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:
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)
3. DataSet daset = ds.Clone();
4. dataGridView2.DataSource = daset.Tables;
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)
3. DataSet daset = ds.Copy();
4. dataGridView2.DataSource = daset.Tables;
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()
3. SqlConnection con = new SqlConnection("your database connection string ");
5. SqlCommand cmd = new SqlCommand("Write your query or procedure ", con);
6. SqlDataAdapter da = new SqlDataAdapter(cmd);
7. DataSet ds = new DataSet();
9. grid.DataSource = ds;
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 technicalsymposium.com Google Group members. Further, this content is not intended to be used for commercial purpose. Technicalsymposium.com is not liable/responsible for any copyright issues.
Placement Materials PDF-Free Download
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