What is sequence of code in retrieving data from database ?

Answers were Sorted based on User's Feedback



What is sequence of code in retrieving data from database ?..

Answer / senthil kumar

if you use sql server
SqlConnection con = new SqlConnection();
con.ConnectionString ="Data Source=servername;Initial
Catalog=databasename;";
con.Open();
String sql;
sql ="select * from tbl_tablename";
SqlCommand cmd = new SqlCommand(sql,con);
SqlDataReader reader;
reader = cmd.ExecuteReader();
while(reader.Read)
{
Console.WriteLine("Field1:"+read.GetString(0));
Console.WriteLine("Field1:"+read.GetString(1));
Console.WriteLine("Field1:"+read.GetValue(2));
}
con.Close();
}

Is This Answer Correct ?    9 Yes 4 No

What is sequence of code in retrieving data from database ?..

Answer / 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

What is sequence of code in retrieving data from database ?..

Answer / payal

//In this answer there is sqlserver
/*i write this code in vb.net with windows applications and
use sql server provider*/
//first need namespace

system.data.sqlclient
//need connection,command,connection string

dim sqlcmd as sqlcommand
dim sqlcon as sqlconnection
dom da as sqldataadaptor
dim ds as dataset
dim constr as sting="user
password=sss;datasource=sds;initial catalog=fgf"

/*connection string give all details about database
connection initial catalog means data base name and data
source is sqlserver name,user id and password also*/

//open connection and pass connection string

sqlcon=new sqlconnection(constr)
sqlcon.open()

//create new object of command with new keyword

sqlcmd=new sqlcommand("select * from tablename",sqlcon)

/*data adapter is mediater between the data base and data
set because dataset is work in disconneted mode.*/

da=new sqldataadaptor(sqlcmd)

/*data adapter fetch query to data base and get answer and
fil the dataset using fill*/

da.fill(ds)

/*there is datagird which i use for display data on
form.data from dataset i use this bind to datagrid*/

datagird.datasource=ds.tables("table name")

Is This Answer Correct ?    4 Yes 2 No

Post New Answer

More ADO.NET Interview Questions

What is ole in vb?

0 Answers  


How to get oledb connection?

3 Answers  


If a table contains 20000 records . In a page at each time 100 records to be displayed what are the steps you will take to improve performance? Will you use dataset or datareader?

0 Answers  


What is a datareader object?

0 Answers  


Difference between DataReader and DataAdapter / DataSet and DataAdapter?

3 Answers   TCS,






What is execute scalar in ado.net?

0 Answers  


Which object holds only data and does not interact with data source?

0 Answers  


What is ado.net and its features?

0 Answers  


What provider ado.net use by default? Explain the role of data provider in ado.net? What is the role of data provider in ado.net?

0 Answers  


What are the advantages of ado.net?

0 Answers  


what is the difference betwen typed dataset and untyped dataset?in general which dataset can we use in programming?

0 Answers   EDS,


How many major types of connection objects in ADO.NET?

0 Answers   MCN Solutions,


Categories