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 basic use of data view?

503


Can we load multiple tables in a dataset?

530


What is the difference between OLEDB Provider and SqlClient?

519


Which is better ole db or odbc?

488


What is isolation?

561






Explain the difference in an abstract class and an interface?

489


Explain the difference between sqlcommand object and command behavior object?

522


can we create synonymn in ms access,sql server,my sql if so explain me with example

1566


What does executenonquery () method return?

491


Explain the advantages and disadvantages of using datalist?

602


What DataReader class do in ADO.NET ?

574


Which ado.net object is very fast in getting data from the database?

631


Describe briefly an ADO.NET Dataset ?

538


What is the difference between statement and preparedstatement interface?

558


Why ca not we use multiple inheritance and garbage collector paralelly in .net?

544