Solved

Insert/Update from GridView

Posted on 2006-06-19
4
6,553 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

705 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