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 are three common acronyms used in .net, and what do they stand for?

625


Explain what is reflection in microsoft .net context?

644


what will do to avoid prior case?

682


What should you do to store an object in a viewstate?

644


What is the difference between web application and enterprise application?

650






What are the differences between user control and server control?

693


Can you edit data in repeater control? How?

632


hai, about trading domain and need simple project on trading system. please help me...

1655


What tools can I use to develop .net applications?

648


Explain the difference between garbage collections in .net 4.0 and earlier versions?

625


Please explain what is heap and what is stack?

652


What does il do?

635


Explain Creational design pattern in .NET?

711


What are the purposes of using .net?

691


How to implement datagrid in.net? How would you make a combo-box appear in one column of a datagrid? What are the ways to show data grid inside a data grid for a master details type of tables? If we write any code for datagrid methods. What is the access specifier used for that methods in the code behind file and why?

632