DataSets vs Queries
-
I have a couple of different procedures that retrieve data from a single database. Both return a single value, either an Integer or DateTime. But the one that returns an integer accesses the data by connecting to the database and returning the data using .ExecuteScalar, while the other one builds a DataAdapter, a DataSet, and a DataTable, then references the DataTable to get the data. my question is, is there any advantge to using DataSets over directly query-ing the database?
-
I have a couple of different procedures that retrieve data from a single database. Both return a single value, either an Integer or DateTime. But the one that returns an integer accesses the data by connecting to the database and returning the data using .ExecuteScalar, while the other one builds a DataAdapter, a DataSet, and a DataTable, then references the DataTable to get the data. my question is, is there any advantge to using DataSets over directly query-ing the database?
The difference here is not the dataset or not, it is the data adapter or the execute scalar method. Executescalar returns a single value and will always return a single value. The other query, if it always returns a single value would possibly benefit from using the executescalar method b/c it wont use all that memory overhead with datasets and adapters and such. If you will need to return more than a single value then you have 2 choices really, the dataadapter allows you grab a dataset or fill a datatable - or you can use a datareader. Both return a set of data and have their benefits and problems. So after a long windy explaination - you are querying the database no matter what, but one uses more objects to get the data. Cleako