Advice needed - SQL queries in C#

  • Thread starter Thread starter Kavvy
  • Start date Start date
K

Kavvy

After messing about I've made some headway towards getting a DataSet filled
with data from an SQL database, unfortunately I've been advised that this
isn't the way forward due to the overhead involved of filling the DataSet
with every page access.

So what method is prefereable to use?

Am I supposed to create a DataAdapter that only fetches a certain query,
dependant on what the users type in fields? Or am I supposed to use a
DataSet in the same way?

The book I bought is pretty useless in the respect that it focuses on the
DataSet as the all-encompasing solution to all your needs. Which I debate
TBH.

All I want to do is execute SQL queries and put the results in to text
boxes, then update the SQL tables with an update query afterwards....

Any advice greatly appreciated.
Rich.
 
Kavvy said:
After messing about I've made some headway towards getting a DataSet
filled with data from an SQL database, unfortunately I've been advised
that this isn't the way forward due to the overhead involved of filling
the DataSet with every page access.

So what method is prefereable to use?

Am I supposed to create a DataAdapter that only fetches a certain query,
dependant on what the users type in fields? Or am I supposed to use a
DataSet in the same way?

The book I bought is pretty useless in the respect that it focuses on the
DataSet as the all-encompasing solution to all your needs. Which I debate
TBH.

All I want to do is execute SQL queries and put the results in to text
boxes, then update the SQL tables with an update query afterwards....

Any advice greatly appreciated.
Rich.

You could always use a DataReader to get the data.

Then use a stored procedure to update the database.

As I understand it, the DataSet works best when you have a large grid of
data and you want instant updates back to the database. However, the
Update features of the DataSet has to be congruent with the database table.
You can't update a view, or the product of a join, for example.
 
Kavvy said:
After messing about I've made some headway towards getting a DataSet filled
with data from an SQL database, unfortunately I've been advised that this
isn't the way forward due to the overhead involved of filling the DataSet
with every page access.

So what method is prefereable to use?

Am I supposed to create a DataAdapter that only fetches a certain query,
dependant on what the users type in fields? Or am I supposed to use a
DataSet in the same way?

I normally use a DataSet *with* a DataAdapter - or bypass a DataSet
entirely and just use DataTables directly. (I don't think DataSets
really give that much benefit as a collection, but that could just be
due to the apps I happen to have written not needing the extra
functionality.)

You'd normally have a DataAdapter with a command already populated, and
then set the parameter values of that command from what the user types
in.
The book I bought is pretty useless in the respect that it focuses on the
DataSet as the all-encompasing solution to all your needs. Which I debate
TBH.

All I want to do is execute SQL queries and put the results in to text
boxes, then update the SQL tables with an update query afterwards....

To be honest, using a DataSet (or at least a DataTable) is still
probably the way to go. The only other viable alternative would be to
use a DataReader, which doesn't really buy you much - you might get
*slightly* more efficiency, but your code would be longer and more
fragile.

Using DataTable/DataAdapter will make the update much easier, too.
 
Back
Top