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

Using activex control in .net?

772


What are the difference bbetween value type & reference types ? Example from .net. Integer & struct are value types or reference types in .net?

729


How to create properties and methods using controls?

812


In code behind class, name the type of code found. Is it the server side code or client side code?

1028


What is the base class of Button control in .NET?

814


Define satelite assembly?

775


How will you make .NET programs work in Linux ?

1734


Explain what is the reason of occurring overflow-underflow arithmetic exception error, it shows error message when we run our program by adding control?

767


How can you instantiate a tuple?

778


What is .net and why it is used?

741


What are an object and a class?

781


What is new in .net core?

722


What is the benefit of .net core?

727


Explain soap and xml?

774


explain the states of a window service application?

761