Write steps of retrieving data using ado.net ?

Answer Posted / senthil kumar

we can use two ways to retrieve the data from database
1 -> data reader
2 -> data adapter

when you use datareader
create connection object and open the connection
SqlCommand cmd = new SqlCommand(sql,con);
cmd.CommandType = CommandType.Text;
SqlDataReader sread = cmd.ExecuteReader();
while(sread.Read())
{
String data1 = sread.GetString(0);
int data2 = sread.GetValue(1);
String data3 = sread.GetString(2);
}

when u use the dataadapter

create the connection and open
SqlDataAdapter sda = new SqlDataAdapter(sql,con);
DataSet ds = new DataSet();
sda.Fill(ds,"customer");

then use can get the data in row wise or directly assign
the data to the controls through datasource.

i think its enough.If i did any mistake correct me.

Is This Answer Correct ?    13 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a column variable?

497


Can you explain how to enable and disable connection pooling?

498


Define Execute Scalar?

547


What is csdl entity framework?

547


What are the ado.net objects?

508






How to work with disconnected data - the dataset and sqldataadapter?

498


What are basic methods of dataadapter?

498


If a table contains 20000 records. In a page at each time 100 records to be displayed.

509


Explain ODP.net

565


What is a datareader object?

575


How does ado.net work?

486


Is it possible to edit data in Repeater control?

525


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

507


What is difference between ado.net and asp net?

508


What are the methods of XML dataset object?

611