Hi,
The code below is a simple demonstration of ado.net. You don't have to
use it exactly as I have below. You could have declared and instantiated a
sqlcommand object rather than just have a static sql query in the
dataadapter. The below code is intended to be used with sql server only. If
you wish to use any other database then you need to use the equivavalent
classes for those classes ex: oraConnection, oraCommand, oraAdapter. Dataset
is the object that will hold all the retrieved from the command locally
(disconnected). Only use the datagrid.databind if you are using this code in
asp.net, if you do not do this then you will not be able to view the data
retrieved in.
// declare and instantiate the connection and dataadapter
System.Data.SqlClient.SqlConnection sqlconn = new
System.Data.SqlClient.SqlConnection("connection string here");
System.Data.SqlClient.SqlDataAdapter sqlda = new
System.Data.SqlClient.SqlDataAdapter("command text here", sqlconn);
DataSet ds = new DataSet();
// declare and instantiate a datagrid to hold and present the result of
query
DataGrid dg = new DataGrid();
// fill the result from the query to dataset, data adapter will manage
the open and closing of
// connection so no need to open the connection before hand
ds= sqlda.Fill;
dg.DataSource = ds;
// use this if you are using this code in asp.net other wise no need to
have this command
dg.DataBind();
Hope this helps