Wrox Programmer Forums
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old May 30th, 2008, 10:33 AM
Authorized User
Join Date: Sep 2007
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default VB Adding UpdateCommand

I am adding a database write facility to my DetailsView control. Already I have a selectcommand driven from the select parameter in the parent GridView control.

In the Wrox Press book "Beginning ASP.NET 2.0", the ease with which writing facilities could be added is described using an example where the Configure Data Source wizard is fetching data from a single table. In this particular case, the Advanced button automatically adds relevant code for Update, Insert & Delete commands. However, if the stored procedures option is used, this Advanced button is no longer available.

My select command is extracting data from more than one table in the database. I used the Query Designer within the Configure wizard to build it. My problem is how to construct an equivalent Update command to affect fields in more than one table, e.g.:
Events.EventName, Events.Location, Events.StartDate,
Events.EventDescription, Events.EventID,
Travel.Travel, [Group Photos].ImageURL

Later I will need to modify the delete and insert commands, but once I figure out the update command I'm hoping that the others will fall into place.

Here is my source code. The update command sql shown below is generated by the wizard using a single-table implementation. It needs to change, but it's a starting point:
SelectCommand="SELECT Events.EventName, Events.Location, 
Events.StartDate, Events.StartTime, Events.EventDescription, 
Events.EventID, Travel.Travel, [Group Photos].ImageURL 
FROM Events 
INNER JOIN [Group Photos] ON Events.EventID = [Group Photos].EventID 
INNER JOIN Travel ON Events.EventID = Travel.EventID 
WHERE (Events.EventID = @EventID)" 

UpdateCommand="UPDATE [Events] SET [EventName] = @EventName,
[Location] = @Location, 
[StartDate] = @StartDate, 
[EventDescription] = @EventDescription 
WHERE [EventID] = @original_EventID"

InsertCommand="INSERT INTO [Events] ([EventName], [Location],
[StartDate], [EventDescription]) 
VALUES (@EventName, @Location, @StartDate, @EventDescription)" 

DeleteCommand="DELETE FROM [Events] 
WHERE [EventID] = @original_EventID ...
I can provide more code if it would help. As I'm a newbie, I'm not delving into code-behind yet.

Rugeley, UK
WinXP Pro SP2
VBW Express + SQL Server 2005 Express
Rugeley, UK
WinXP Pro SP2
VBW Express + SQL Server 2005 Express

Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView UpdateCommand Sheraz Khan ASP.NET 2.0 Professional 2 August 28th, 2007 07:24 AM
Adding a Checkbox to a FlexGrid using VB 6.0 foka VB Components 1 June 9th, 2007 05:13 AM
Adding a Checkbox to a FlexGrid using VB 6.0 foka VB Components 3 March 8th, 2006 07:58 AM
the UpdateCommand affected 0 of the expected 1 rec theRealAirness ADO.NET 0 March 28th, 2005 04:23 PM
UpdateCommand ozzy VB.NET 2002/2003 Basics 4 January 24th, 2005 05:55 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.