Updating a gridview with a joined table select statement

Using Visual Studio 2005 asp.net
I have a gridview that I populate with a select statement that joins two tables.
Select events.*, eventtype.label
From events, eventtype
Where events.eventtypeID = eventtype.eventtypeID
The update will update the events table.
I cannot get the update to work with the joined field.  Is there a property I can set to make this work or will I need to figure another way??
PEAKTTAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vbsquickresponseCommented:
I think instead of using SQLDataSource, I suggest you to use ObjectDataSource where it gives you flexible of Select, Insert, updating as you need.

Do some expore on ObjectDataSource
0
Juan_BarreraCommented:
@vbsquickresponse:

But SqlDataSource does it as well (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.updatecommand.aspx).

@PEAKTT
Can you please post the SQL statement you use for the SqlDataSource.UpdateCommand property?
0
lotusnotesnewbieCommented:
<asp:SqlDataSource ID="display" runat="server" ConnectionString="<%$ ConnectionStrings:myprojDB %>"
SelectCommand="SELECT customer.[UserId],[aspnet_Membership].[Email], aspnet_Users.[UserName], [fname] FROM [customer] JOIN [aspnet_Users] ON [customer].[UserId] = [aspnet_Users].[UserId]  JOIN [aspnet_Membership] ON [aspnet_Users].[UserId] = [aspnet_Membership].[UserId] WHERE (customer.[UserId] = @UserId)"
UpdateCommand="UPDATE [customer] SET [fname] = @fname WHERE [UserId] = @UserId">
                                            <UpdateParameters>
                                                <asp:Parameter Name="fname" Type="String" />
                                            </UpdateParameters>
                                            <SelectParameters>
                                                <asp:ControlParameter ControlID="grdCustomers" Name="UserId" PropertyName="SelectedValue" Type="Object" />
                                            </SelectParameters>
                                        </asp:SqlDataSource>

This works for me!!! I not so clear about your question. See if this helps or le me know what u r looking for exactly
0
PEAKTTAuthor Commented:
This is my SQL statement code:

I am using the select command to fill the gridview rows.  Each row will have an Edit button.
I then use the update command to edit the rows.

These statements are what I am using.  As is the update does not work.  If I take out the field from the joined table, it works just fine.  I have the gridview set with enable editing and the datakeynames set to the key field.

Any Ideas??
SelectCommand="SELECT SubpeonaExhibitFields.SubpeonaExhibitFieldsID, SubpeonaExhibitFields.SubpoenaID, SubpeonaExhibitFields.ProvideriD, SubpeonaExhibitFields.ExhibitID, SubpeonaExhibitFields.ExhibitFieldsID, SubpeonaExhibitFields.ExhibitFieldValue, SubpeonaExhibitFields.ModifiedDate, SubpeonaExhibitFields.ModifiedBy, ExhibitFields.ExhibitLabel FROM SubpeonaExhibitFields LEFT OUTER JOIN ExhibitFields ON SubpeonaExhibitFields.ExhibitFieldsID = ExhibitFields.ExhibitFieldsID WHERE (SubpeonaExhibitFields.SubpeonaExhibitFieldsID = @SubpeonaExhibitFieldsID) ORDER BY SubpeonaExhibitFields.ExhibitFieldsID" 
                    UpdateCommand="UPDATE SubpeonaExhibitFields SET SubpoenaID = @SubpoenaID, ProvideriD = @ProvideriD, ExhibitID = @ExhibitID, ExhibitFieldsID = @ExhibitFieldsID, ExhibitFieldValue = @ExhibitFieldValue, ModifiedDate = GETDATE(), ModifiedBy = @ModifiedBy WHERE (SubpeonaExhibitFieldsID = @SubpeonaExhibitFieldsID)" 
                    DeleteCommand="DELETE FROM [SubpeonaExhibitFields] WHERE [SubpeonaExhibitFieldsID] = @SubpeonaExhibitFieldsID" 
                    InsertCommand="INSERT INTO [SubpeonaExhibitFields] ([SubpoenaID], [ProvideriD], [ExhibitID], [ExhibitFieldsID], [ExhibitFieldValue], [ModifiedDate], [ModifiedBy]) VALUES (@SubpoenaID, @ProvideriD, @ExhibitID, @ExhibitFieldsID, @ExhibitFieldValue,getdate(), @ModifiedBy)">

Open in new window

0
PEAKTTAuthor Commented:
I found that if you add all the key fields to the DataKeyNames property you can have them hidden when displaying the gridview yet use them for editting.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.