using a SQLDataSource in Code

  • Thread starter Thread starter GaryDean
  • Start date Start date
G

GaryDean

I use SQLDataSources all the time to drive various controls such as
Gridviews. But now I'm trying to pick data out of one using c# code-behind.
There is no items collection. So far I can't figure out how to get at the
data.
Anyone know?
Thanks,
T
 
The only way I found to get data directly from the SQLDataSource is from its
parameters collection. If you use output parameters for the data, you could
retrieve it that way. I agree with you- seems like there should be something
more direct, but I couldn't find it either.

My alternative was to retrieve data from the gridview rather than the
sqldatasource. In the GV rowdatabound event you can use something like this:
System.Data.DataView dataAuthors = (e.Row.DataItem as
System.Data.DataRowView).DataView;

In a DetailsView ItemInserted, ItemUpdated or ItemDeleted event you can
retrieve data from the event argument with e.Values or e.NewValues. Probably
something similar for a GridView?
 
I use SQLDataSources all the time to drive various controls such as
Gridviews.  But now I'm trying to pick data out of one using c# code-behind.
There is no items collection.  So far I can't figure out how to get at the
data.
Anyone know?
Thanks,
T

The DataSource controls in ASP.NET 2 are designed purely for
populating visual databound controls.They were never intended as a
means of accessing data programatically which is why there are no
public properties or methods that enable it.

The alternative are typed DataSets that are added to the App_Code
folder. Within these objects you can define TableAdapters using the
Visual Studio wizards that configure them. TableAdapters have the
functionality required for retrieving data from the database directly
or for filling typed DataSet tables. They also support insert, delete
and update operations as well as the use of stored procedures.

Essentially, DataSource and typed DataSets are the successors to
DataAdapters that were used for both purposes in version 1 of ASP.NET

HTH
 
I use SQLDataSources all the time to drive various controls such as
Gridviews. But now I'm trying to pick data out of one using c#
code-behind.
There is no items collection. So far I can't figure out how to get at the
data.
Anyone know?
Thanks,
T

The DataSource controls in ASP.NET 2 are designed purely for
populating visual databound controls.They were never intended as a
means of accessing data programatically which is why there are no
public properties or methods that enable it.

The alternative are typed DataSets that are added to the App_Code
folder. Within these objects you can define TableAdapters using the
Visual Studio wizards that configure them. TableAdapters have the
functionality required for retrieving data from the database directly
or for filling typed DataSet tables. They also support insert, delete
and update operations as well as the use of stored procedures.

Essentially, DataSource and typed DataSets are the successors to
DataAdapters that were used for both purposes in version 1 of ASP.NET

HTH

You can use dataReader, Entity Framework, DataSets, LINQ to sql and so on.
 
Back
Top