Kapalic

Hi Gurus,

Good day! Back with another concept requirement!!

Which approach I should take in handling data modification - Stored Procedure or DataAdapter + DataSet

I mean, should I use stored procedures for every of my data modification operation like adding, editing, deleting tasks Or I should fill a dataset with a data adapter and perform the data modification in the dataset and update the database

Thnx again for your great helps!

Regards

Kapalic!




Re: .NET Framework Data Access and Storage Handling data modification

VMazur

Conceptually those are two distinct parts. Stored procedures or queries allow you to do some actions against database and they have nothing to do with the DataSet or DataAdapter. DataSet is some sort of in-memory database that allows keeping data on a client side and it is completely database independent. DataAdapter is a bridge between DataSet and your database that allows loading data from database into DataSet/DataTable and moving changes back from DataSet/DataTable to the database. And to do those actions DataAdapter calls stored procedure or SQL statement to accomplish both tasks. You also could update database using SP or SQL without using DataAdapter calling them using Command






Re: .NET Framework Data Access and Storage Handling data modification

Kapalic

Hi VMazur,

Actually I couldn't explain my problem properly.

I wanted to know, for the data operation, should I use the add, edit, delete method in the dataset and update the dataset, or exclusively use stored procedure to do those operations. Which will be better

Thnx for reply.

Kapalic






Re: .NET Framework Data Access and Storage Handling data modification

WineNCheese

The methods on an ADO.NET dataset will not result in changes to the database contents, as the dataset works in a disconnected state. You need to use a DataAdapter for each table, which adapts the data to whatever the source is (in your case, a database). The dataadapters can be configured to use stored procedures or inline SQL.

I think the question you may be asking is should you directly call stored procs from your code to fill your data model, or use the dataadapter/dataset approach. Except for extremely simple scenarios (and maybe even those) I'll always opt for the latter because it gives you the DataSet as a convenient way of storing your data, as well as many powerful means for manipulating the data.

WNC






Re: .NET Framework Data Access and Storage Handling data modification

Kapalic

Hi WNC,

Thnx a lot for your reply. Yes, I wanted to mean exactly what you mean! Let me explain my situation with an example.

I have a table named Machines which has two fields - MachineID, MachineName. To modify the data in this table, I have a form with a DataGreedView and two Textbox. I have buttons in this form name Add, Save, Cancel, Update, and Delete. Now you can see what I want to do with this form.

I feel a Dataset with a DataAdapter with this full table, and bind the grid and text boxes with the dataset. Now I can use the add, update, delete method to modify data.

In another case, I can use a sproc to add data, another for update and delete respectly, which i can run from my buttons with the help of a Command object.

What I want to know is, which approach is better What is the advantage and disadvantages of these aproaches

I think I could make myself a bit clearer!

Best Regards!!

Kapalic






Re: .NET Framework Data Access and Storage Handling data modification

VMazur

It depends on what you need to achieve in your application. If there is a need to store (cache) data inside of the application and work with it, then DataSet is a good storage and DataAdapter is a good mechanism to move data to the database. Remember that DataTables inside of the DataSet have possibility to select data, sort it using DataViews and do additional staff that could be expensive when you work directly with the database, and DataSets could provide benefits in this case.

On other hand, if you need to get output from the client and store it into the database, there is no need to keep it in a DataSet and spend additional resources to maintain it. In this case call SQL statement or stored procedure directly would be simpler approach.






Re: .NET Framework Data Access and Storage Handling data modification

Kapalic

Hi VMazur,

Thank you so much for your reply. The fact is clear to me now. I thought using the sprocs is expensive than dataset/adapter, which I see now is wrong. I'll be using sprocs for my applications then.

Best Regards!

Kapalic