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

What is delegation in .net?

812


Please explain what is the difference between a class and an object?

792


What is the advantage of .net core?

743


What is .net latest version?

771


Is the COM architecture same as .Net architecture? What is the difference between them (if at all there is)?

1769


What are the core differences between .NET Languages ?

1986


Explain why do we use the “using” statement?

795


i m fresher,hav SQL knowledge but in my ofc. i hav to work on dotnet. so plz tell me how to learn it,? from where to stat? i hav C prog. knowledge, ASP.net

2366


Using activex control in .net?

746


What is .net code security?

767


What is web.config in .net?

773


How ccw (com callable wrapper) and rcw (runtime callable wrappers) works?

770


What is DTS and explain the purpose of it?

804


What is heap and what is stack?

791


What is .net technology?

788