What is sequence of code in retrieving data from database ?

Answer Posted / manoj batra

If using DataSet :
1) Create a connection object
2) Create a DataAdapter object
3) Associate your query and connection with DataAdapter
4) Create DataSet object
5) Fill the dataset with desired result using Fill method of
DataAdapter.
6) start retriving the data into your container from dataset.
Note : DataAdapter automatically Open and Close the connection.

If using DataReader:
1) Create connection object
2) Oen connection
3) Create Command object
4) Create DataReader object
5) Associate your Sql command with the command object
6) Use ExecuteDataReader method inside the loop (The
selective Sql query may return more than one Row)
Note : DataReader is Readonly and ForwardOnly operation.
7) Return result in control(s).
8) Close the connection

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the steps to connect to a database?

637


Explain why canot we use multiple inheritance and garbage collector paralelly in .net?

678


What are typed and untyped dataset?

639


What is sqldatareader in ado.net?

576


What are the pre-requisites for connection pooling?

620






What is difference between datagridview and datagrid control in winforms?

590


Define different execute methods of ADO.NET command object ?

629


What is the role of data provider in ado.net?

625


What is openquery?

606


What are the rules to implement connection pooling?

583


How can I retrieve two tables of data at a time by using data reader?

596


What are dcl commands?

577


What we do with the object of ado.net dataset after using it?

591


What are the advantages of using datalist?

589


What is basic use of data view?

601