syntax for binding the data from database



syntax for binding the data from database..

Answer / sambhu sankar biswal

Actually There is no syntax to bind data from data base.

to bind data from data base
1st step:-create connection to database
2nd step:-write command
3rd step:-create object of data adapter(oledb/sql)
4th step:-create object of dataset
5th step:-dataadapter's object name.fill(dataset's object name);
6th step:-control name(where u have to bind the
data).DataSource=dataset's object name;
7th step:-control name(where u have to bind the
data).DataBind();



Example:-suppose we need to bind data from "emp" table to
gridview control


Code is bellow:-

Using system.Data.Oledb;//Name space

//inside page load event

OledbConnectionn cn=new
OledbConnection("provider=microsoft.jet.oledb.4.0;data
source=c:/db2.mdb");//complete path of the data base.
OledbCommand cmd=new OledbCommand("select * from emp",cn);
OledbDataAdapter da=new OledbDataAdapter(cmd);
DataSet ds= new DataSet();
da.fill(ds);
GridView1.DataSource=ds;
GridView1.DataBind();

Is This Answer Correct ?    7 Yes 0 No

Post New Answer

More Dot Net General Interview Questions

What is serialization in .NET? What are the ways to control serialization?

1 Answers  


If you are executing these statements in commandobject. Select * from table1; select * from table2? How you will deal result set? 42. How do you sort a dataset.

0 Answers  


Garbage collector thread is what kind of a thread?

1 Answers  


Can you edit data in repeater control? How?

0 Answers  


Please explain what is heap and what is stack?

0 Answers  


Explain the difference between asp.net and asp?

0 Answers  


what is the use of "mustinherit" keyword?

2 Answers  


Explain the difference between the while and for loop.

0 Answers  


What is boxing and un-boxing in .net?

0 Answers  


Describe session handling in a webform, how does it work and what are the limitations?

0 Answers  


What is a .net class?

0 Answers  


What is assembly in .net?

0 Answers  


Categories