?
Solved

Insert/Update from GridView

Posted on 2006-06-19
4
Medium Priority
?
6,558 Views
Last Modified: 2010-05-18
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

0
Comment
Question by:raterus
  • 2
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
bele04 earned 2000 total points
ID: 16939320
Since you're dealing with deleting a few rows I'd suggest you go with using a Sql Transaction so that in case something goes wrong later on (probably when your inserting new rows) you could easily just call rollback.  That way you won't be sacrificing any data whenever something goes wrong .  And since you're dealing with probably a whole lot of sql statements here then you might wanna check if your insert will come out ok, if not then popup an error and rollback the changes you made to the database.  

Maybe you could do with the Insert first before you go on with the Deleting of rows that way you can save some processing time with the delete command in case something goes wrong with the Insert commands.  Still using the SqlTransaction...
0
 
LVL 33

Author Comment

by:raterus
ID: 16941727
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!
0
 
LVL 9

Expert Comment

by:bele04
ID: 16948113
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.  
0
 
LVL 33

Author Comment

by:raterus
ID: 16950717
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.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question