ADO.NET Interview Questions for Freshers and Experienced


1.      Advantages of ADO.Net?

1.      ADO.NET Does Not Depend On Continuously Live Connections
2.      Database Interactions Are Performed Using Data Commands
3.      Data Can Be Cached in Datasets
4.      Datasets Are Independent of Data Sources
5.      Data Is Persisted as XML
6.      Schemas Define Data Structures
2.      How would u connect to database using .NET?

SqlConnection nwindConn = new SqlConnection("Data Source=localhost;
             Integrated Security=SSPI;" + "Initial Catalog=northwind");
nwindConn.Open();

3.      What are relation objects in dataset and how & where to use them?

In a DataSet that contains multiple DataTable objects, you can use DataRelation objects to relate one table to another, to navigate through the tables, and to return child or parent rows from a related table. Adding a DataRelation to a DataSet adds, by default, a UniqueConstraint to the parent table and a ForeignKeyConstraint to the child table. 

The following code example creates a DataRelation using two DataTable objects in a DataSet. Each DataTable contains a column named CustID, which serves as a link between the two DataTable objects. The example adds a single DataRelation to the Relations collection of the DataSet. The first argument in the example specifies the name of the DataRelation being created. The second argument sets the parent DataColumn and the third argument sets the child DataColumn.

custDS.Relations.Add("CustOrders",
custDS.Tables["Customers"].Columns["CustID"],
custDS.Tables["Orders"].Columns["CustID"]);

(OR)

private void CreateRelation()
{
 // Get the DataColumn objects from two DataTable objects in a DataSet.
DataColumn parentCol;
DataColumn childCol;
// Code to get the DataSet not shown here.
parentCol = DataSet1.Tables["Customers"].Columns["CustID"];
childCol = DataSet1.Tables["Orders"].Columns["CustID"];
// Create DataRelation.
DataRelation relCustOrder;
relCustOrder = new DataRelation("CustomersOrders", parentCol, childCol);
// Add the relation to the DataSet.
DataSet1.Relations.Add(relCustOrder);
}

4.      Difference between OLEDB Provider and SqlClient?

SQLClient .NET classes are highly optimized for the .net / sqlserver combination and achieve optimal results. The SqlClient data provider is fast. It's faster than the Oracle provider, and faster than accessing database via the OleDb layer. It's faster because it accesses the native library (which automatically gives you better performance), and it was written with lots of help from the SQL Server team.

5.      What are the different namespaces used in the project to connect the database?
                                                            (OR)
6.      What data providers available in .net to connect to database?

            System.Data.OleDb – classes that make up the .NET Framework Data Provider for OLE DB-compatible data sources. These classes allow you to connect to an OLE DB data source, execute commands against the source, and read the results.
           
System.Data.SqlClient – classes that make up the .NET Framework Data Provider for SQL Server, which allows you to connect to SQL Server 7.0, execute commands, and read results. The System.Data.SqlClient namespace is similar to the System.Data.OleDb namespace, but is optimized for access to SQL Server 7.0 and later.

System.Data.Odbc - classes that make up the .NET Framework Data Provider for ODBC. These classes allow you to access ODBC data source in the managed space.

System.Data.OracleClient - classes that make up the .NET Framework Data Provider for Oracle. These classes allow you to access an Oracle data source in the managed space.


7.      Which method do you invoke on the DataAdapter control to load your generated dataset with data?

Fill()

8.      Explain different methods and Properties of DataReader which you have used in your project?

Read
GetString
GetInt32 while (myReader.Read())
Console.WriteLine("\t{0}\t{1}", myReader.GetInt32(0), myReader.GetString(1));
myReader.Close();

9.      What happens when we issue Dataset.ReadXml command?

Reads XML schema and data into the DataSet.

10.  In how many ways we can retrieve table records count? How to find the count of records in a dataset?

foreach(DataTable thisTable in myDataSet.Tables)
{
}
// For each row, print the values of each column.
foreach(DataRow myRow in thisTable.Rows)
{
}

11.  How to check if a datareader is closed or opened?

IsClosed()

12.  Differences between dataset.clone and dataset.copy?

Clone - Copies the structure of the DataSet, including all DataTable schemas, relations, and constraints. Does not copy any data.
Copy - Copies both the structure and data for this DataSet.

No comments:

Post a Comment