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

Explain me what is .net web service?

563


Please explain what is heap and what is stack?

577


What are the new features in .net core?

555


Explain me what is encapsulation?

553


Please explain what is reflection and what is it for?

504






Explain how garbage collection works?

582


What is the concept of inheritance in .net?

609


What is data type and how many types of data types are in .NET ?

560


What is the difference between user control an custom control? Advantages/disadvantages?

579


What is web.config in .net?

593


Do you know what is linq?

592


What is a variable of implicit type and what is its scope?

516


How to use datagrid value in select statements where condition ,if cell is hyperlink bounded column?

535


What are the main components in .net?

538


What is lazy initialization?

595