Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Insert/Update from GridView

Posted on 2006-06-19
4
Medium Priority
?
6,556 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 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

610 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