Ado Net Dataset Dataset
Ado Net Dataset Dataset
NET QUESTIONS
1. What is an ADO.Net?
ADO.NET is used to communicate with database for data access. We can perform all types of CRUD operations
with database using ADO.NET
Microsoft ActiveX Data Objects (ADO).
ADO.NET is a set of classes that can be used to interact with data sources like databases and XML files.
18. What are the differences between OLEDB and SqlClient Providers?
OleDb and SqlClient are both called as Data Providers in .net
OLEDB Provider use to connect Access , Excel etc and SqlClient use to connect with SqlServer or SqlData
File
They are basically namespaces which contain specific classes used for connectivity and for
data handling.
OleDb is referred to as System.Data.OleDb
SqlClient is referred to as System.Data.SqlClient.
OleDb: Object linking and Embedding database.
Differences:
OleDb is used for connecting to any database like SQL Server (For SQL Server 6.5 or lower we will have to
use OleDb), Access, Excel.We have to mention the appropriate provider to connect with the particular
database.This adds an extra layer for connetion and has performance impacts or Performance is not so faster..
SqlClient is used for SQL Server only (for SQL Server 7.0 onwards) We do not have to mention the SQL
Server provider.
SqlClient is faster than OleDb.
ExecuteNonQuery This method executes the command specifies and returns the number of rows affected.(integer)
The ExecuteReader method executes the command specified and returns an instance of
ExecuteReader
SqlDataReader class.
This method executes the command specified and returns the first column of first row of the result
ExecuteScalar
set. The remaining rows and column are ignored.
ExecuteXMLReade This method executes the command specified and returns an instance of XmlReader class. This
r method can be used to return the result set in the form of an XML document
20. What are all the commands used with Data Adapter?
InsertCommand , UpdateCommand , and DeleteCommand get on the adapter object.
DataSet.Copy copies both the structure (tables, relations etc) and the data.In other word the Copy method of the
DataSet class copies both the structure and data of a DataSet object. It returns a new DataSet object having the
same structure including all DataTable schemas, relations, and constraints and data as the existing DataSet object.
DataSet.Clone copies only the structure of the DataSet.In other word the Clone method of the DataSet class
copies only the schema of a DataSet object. It returns a new DataSet object that has the same schema as the
existing DataSet object, including all DataTable schemas, relations, and constraints. It does not copy any data
from the existing DataSet object into the new DataSet.
22. What is the difference between Command and CommandBuilder object?
a) SQLCommand is used to execute all kind of SQL queries like DML(Insert, update, Delete) & DDL
like(Create table, drop table etc.)
b) SQLCommandBuilder object is used to build & execute SQL (DML) queries like select, insert, update &
delete.
GetXml( ) Retrieves the XML representation of the data in the DataSet as a single string.
GetXmlSchema( ) Retrieves the XSD schema for the DataSet XML as a single string. No data is returned.
Reads XML data from a file or a TextReader, XmlReader, or Stream object, and uses it to
ReadXml( )
populate the DataSet. The XML document can include an inline schema.
Reads an XML schema from a file or a TextReader, XmlReader, or Stream object, and uses
ReadXmlSchema( )
it to configure the DataSet (for example, creating Constraint and DataColumn objects).
Writes the contents of the DataSet to a file or a TextWriter, XmlWriter, or Stream object.
WriteXml( )
You can choose to write the schema inline.
Writes just the XSD schema describing the contents of the DataSet to a file or
WriteXmlSchema( )
a TextWriter, XmlWriter, or Stream object.
Infers the XML schema and applies it to the DataSet by reading through an XML document
InferXmlSchema( )
supplied by a file or a TextReader, XmlReader, or Stream object.
26. What are all the different authentication techniques used to connect to MS SQL Server?
SQL Server supports two authentication modes, Windows authentication mode and mixed mode.
Windows authentication is the default, and is often referred to as integrated security because this SQL Server
security model is tightly integrated with Windows. Specific Windows user and group accounts are trusted to log in
to SQL Server. Windows users who have already been authenticated do not have to present additional credentials.
Mixed mode supports authentication both by Windows and by SQL Server. User name and password pairs are
maintained within SQL Server.
27. Which method is used by command class to execute SQL statements that return single value?
SqlCommand.ExecuteScalar Method
28. Tom is having XML document and that needs to be read on a daily basis. Which method of XML object
is used to read this XML file?
Reads XML data from a file or a TextReader, XmlReader, or Stream object, and uses it to
ReadXml( )
populate the DataSet. The XML document can include an inline schema.
35. Which is the best method to get two values from the database?
36. What are all the classes that are available in System.Data Namespace?
The six ADO.NET namespaces are the System.Data, System.Data.Common, System.Data.Oledb,
Microsoft.Data.Odbc, System.Data.SqlClient, and System.Data.SqlTypes.
The System.Data namespace is the core namespace of ADO .NET. It consists of the base classes for the
ADO.NET architecture. All data providers use these classes. It defines classes that represent table, columns,
row, and datasets some common classes from this namespace DataView, DataViewManager DataSet,
DataTable, DataRow, DataColumn, and DataRelation. To use these classes in your applications, you need to
add a reference to the System.Data namespace.
Connection, Command, DataReader, DataAdapter.
37. What is the default Timeout for SqlCommand.CommandTimeout property?
The default value is 30 seconds. Avoid a value of 0, which indicates an indefinite wait.
public static void Main() {
string connectionString = "";
// Wait for 5 second delay in the command
string queryString = "waitfor delay '00:00:05'";
using (SqlConnection connection = new SqlConnection(connectionString)) {
connection.Open();
SqlCommand command = new SqlCommand(queryString, connection);
// Setting command timeout to 1 second
command.CommandTimeout = 1;
try {
command.ExecuteNonQuery();
}
catch (SqlException e) {
Console.WriteLine("Got expected SqlException due to command timeout ");
Console.WriteLine(e);
}
}
38. What are the classes in System.Data.Common Namespace?