Sunday, 1 September 2013

40 - ADO.NET Interview Questions

1. In which namespace is the DataSet class present?
Ans. System.Data

2. Is it possible to add more than one table in DataSet?
Ans. Yes

3. Is there a way to clear all the rows from all the tables in a DataSet at once?
Ans. Yes, use the DataSet.Clear() method to clear all the rows from all the tables in a DataSet at once.

4. What is the difference between DataSet.Copy() and DataSet.Clone()?
Ans. DataSet.Clone() copies the structure of the DataSet, including all DataTable schema, relations, and constraints but it does not copy any data.
DataSet.Copy() copies both the structure and data.

5. What is the use of DataSet.HasChanges() Method?
Ans. DataSet.HasChanges method returns a boolean true if there are any changes made to the DataSet, including new, deleted, or modified rows and returns false if there are no changes made to the DataSet.

6. How do you roll back all the changes made to a DataSet since it was created?
Ans. Invoke the DataSet.RejectChanges() method to undo roll back all the changes made to a DataSet since it was created.

7. What is the DataSet.CaseSensitive property?
Ans. When you set the CaseSensitive property of a DataSet to true, string comparisons for all the DataTables within the dataset will be case sensitive. By default the CaseSensitive property is false.

8. What is the difference between DataReader, DataSet and DataAdapter?
Ans. DataReader Provides Read-only Data Which can not be modified by us, Dataset Retrieves data which can be modified by us, DataAdapter is a bridge between dataset and SQL server.

9. What is the difference between ExecuteScalar() and ExecuteNonQuery() methods?
Ans. ExecuteScalar() is used to fetch single value while ExecuteNonQuery() is used to execute insert,update,delete queries.

10. What are the components of ADO.NET?
Ans. The components of ADO.Net are Dataset, DataReader, DataAdapter, Command, connection.

11. What is Maximum Pool Size in ADO.NET Connection String?
Ans. The maximum pool size determines the maximum number of connection objects to be pooled.

12. How to enable and disable connection pooling?
Ans. In connection, we write Pooling=true for enabling connection pooling and Pooling=false for disabling connection pooling.

13. What is DataSet?

Ans. DataSet is the collection of DataTables.

14. What is DataTable?

Ans. DataTable is used to store data in row and column form, we can perform operations like insert, update delete on DataTable.

15. Define methods of DataSet.

Ans. AcceptChanges() ,Clear() , Clone(), Copy(),RejectChanges(), HasChanges(),GetChanges().

16. What is the use of SqlConnection Class?

Ans. SqlConnection Class is used to establish a connection between the database and the front end.

17. What is the use of DataAdapter?

Ans. DataAdapter Fills data from Query to DataSet/DataTable.

18.Which Object is used to get data very fast?

Ans. SqlDataReader

19. What is the default timeout for SqlCommand.CommandTimeout?

Ans. 30 seconds>

20. Can we use StoredProcedure in ADO.Net?

Ans. Yes

21. What is DataView?

Ans. DataView is used to customize the data stored in DataTable. By default, every DataTable has one DataView attached to it.

22. What are the two types of transactions used in ADO.net?

Ans. Local transaction
         Distributed transaction

23. What is a DataRelation Class?
Ans. DataRelation class is found in System.Data namespace. Which defines the relation of two DataTables.
DataRelation drel; 
drel = new DataRelation("All", ds.Tables[0].Columns[0], ds.Tables[1].Columns[0]);

24. What is the use of SqlCommand object?

Ans. SqlCommand is used to query the database like select, insert, update, delete.

25. Is it possible to edit data in Repeater control?

Ans. No

26. What is the ExecuteXMLReader method of Ado.net?

Ans. This method builds the XMLReader object from SQL query.

27. What is the difference between Command and CommandBuilder object?

Ans. Command is used to execute all kind of queries like DDL and DML and CommnadBuilder is used to execute DDL queries.

28. Is it possible to load multiple tables in DataSet?

Ans. Yes , we can load multiple tables in DataSet.

29. Which Data providers are used in ADO.Net?

Ans. ODBC
         MS SQL SERVER
         OLEDB

30. What are different layers of ADO.Net?

Ans. There are 3 different layers of ADO.Net.
         1. Presentation Layer
         2. Business Logic Layer
         3. Database Access Layer

31. Explain DataAdapter.Update() method.

Ans. DataAdapter.Update() method is used to call any of the DML statements like Update, Insert, Delete.

32. Which architecture is followed by DataSets?

Ans. Disconnected

33. What is the difference between close() and dispose() method?

Ans. If we close the connection using close() method it can be opened again
         If we close the connection using dispose() method we can not open it again

34. What are the types of Databinding?

Ans. There are two types of Databinding
         1.  Simple Data Binding: Control is binded to single data element
         2. Complex Data Binding: Control can be binded to single or multiple Data elements.

35. What are the rules to implement connection pooling?

Ans.  1. The connection string must same for all users
          2. The UserID must be same for all users

36. What is ReadCommited and ReadUncommited in Transactions?

Ans. By default all the Transactions are ReadCommited. If two persons are accessing the same table then the second person can see the newly inserted record only if the first person commits the Transaction.
If the Transaction is ReadUncommited then the second person can see newly inserted records without commit of the transaction.

37. What are the different command types in commands?

Ans. CommandType.StoredProcedure : If StoredProcedure is used then we have to                 define CommandType as StoredProcedure
         Example: SqlCommand cmd = new SqlCommand("Employee", con);
         cmd.CommandType = CommandType.StoredProcedure;

         CommandType.TableDirect : If simple query is used then by defualt TableDirect               CommandType is used.

         Example : string select = "Select * from EmpTbl";
        SqlCommand cmd = new SqlCommand(select, conn);

38. Which object is used to add a relationship between two DataTables?

Ans. DataSet

39. What are the parameters that control the behavior of connection pooling?

Ans. Pooling
        Max Pool Size
        Min Pool Size
        Connection TimeOut

40. Which properties are used to bind a DataGridView control?

Ans. The DataSource property and the DataMember property is used to bind DataGridView control.
        

No comments:

Post a Comment

Thanks

SQL server tricky questions