Link to home
Start Free TrialLog in
Avatar of raterus
raterusFlag for United States of America

asked on

Insert/Update from GridView

So I'm trying to break down and learn how to work with the SqlDataSource controls, and insert/update from a Gridview.  Here's what I have

I have a Gridview bound from a SqlDataSource control.  The SelectCommand I'm using is a fancy join, so it doesn't follow the standard examples.  I basically need to do the following when I issue an update command.

- Delete all rows for a particular table that have a certain value in a column (I can easily plug this value from a control parameter)
- For each record I've checked (through a GridView/TemplateField/Checkbox), Insert a new row into a table with values, based on other textbox fields in the current row of the GridView.

Can someone give me ideas about how I can best accomplish this?  Being that the process requires multiple SQL statements, I want to wrap the entire deal in a Sql Transaction.  Is that even possible?

Thanks,
--Michael

ASKER CERTIFIED SOLUTION
Avatar of bele04
bele04

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of raterus

ASKER

So you are saying, forget about DataSource controls for this task, and just do it manually (which I've already done by the way).

I'm still at odds about jumping on the DataSource Controls bandwagon, it just seems to me they do a lot of tasks easily, but can't support the full range of operations you'd want to do to a database.  In my opinion, with that said, why even use them to begin with!
Avatar of bele04
bele04

I'm not saying that you have to completely scrap the DataSource controls.  I do agree that they can't fully support all the things you'd want to do with your database but at least it can help lighten up the workload.  Maybe instead of doing the 2 tasks manually, you could probably use another DataSource control to handle those tasks for you.  Probably have another SqlDataSource and in your updating event of your gridview you can just call your second sqldatasource's insert and update commands.  

Hmmm, on the other hand I think it's probably better to go with the manual handling of the operations.  I just remembered that SqlDataSource doesn't have the rollback capability like SqlTransaction has.  Which got me thinking that it'd probably be nice if SqlDataSource did have the capabilities of a SqlTransaction class.  
Avatar of raterus

ASKER

Thanks for your insights on this question, I kept with my manual process, but am using the sqldatasource controls to do selects.  Works...to say the least.