Solved

Insert/Update from GridView

Posted on 2006-06-19
4
6,549 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 500 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now