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 are dcl commands?

0 Answers  


What are the benefits of ADO.NET?

0 Answers   B-Ways TecnoSoft,


Explain which name space is used to get assembly details?

0 Answers  


If we are not returning any records from the database, which method is to be used?

0 Answers  


Describe the command object and its method.

0 Answers  






What does sqldatareader return?

0 Answers  


What is aggregate root?

0 Answers  


Explain how to bind the controls(best practice) comboboxes to the data in the dataset?

0 Answers  


What is the use of connection object in ado.net?

0 Answers   TryTechnicals Pvt Ltd,


What is a dataview?

0 Answers  


i want 2 pass values(enterd in textbox)to table in sql server without using stored procedure in c#.plz tell me code with an example.

5 Answers   Softcon, Tecra,


What is difference between entity framework and ado.net?

0 Answers  


Categories