syntax for binding the data from database

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Compare client server application with n-tier application

516


What tools is used to develop .NET applications?

624


What is the difference between .net 2000 and .net 2005(features)? Which one is better?

522


Is it true that objects don't always get destroyed immediately when the last reference goes away?

567


Please explain is the jit an interpreter?

585






What is a serviced component?

575


Tell us what is a sealed class?

555


Which namespace is require to used XML in .NET?

598


Tell us the difference between managed and unmanaged code?

527


What are the authentication methods in .net?

569


What is delegation in .net?

610


Explain the procedure to add assemly to gac to make it shared one?

571


What is .net code security?

571


What are Attributes in .NET?

585


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.

542