0

I'm trying to pass a guid to the WHERE statement in a gridview. It works for the Select parameters section, but inserts a null value when I try to update the data.

<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:EDUFormConnectionString %>" 
                    
                    SelectCommand="SELECT OSSPERSON.PERSONID,OSSPERSON.FIRSTNAME, OSSPERSON.LASTNAME, OSSPERSON.AorC, OSSPERSON.AGE, OSSPERSON.GENDER FROM OSSPERSON INNER JOIN OSSREGPERSON ON OSSPERSON.PERSONID = OSSREGPERSON.PERSONID INNER JOIN OSSREG ON OSSREGPERSON.REGID = OSSREG.REGID WHERE (OSSREG.GenGuid = @guid)" 
                    UpdateCommand="UPDATE dbo.OSSPERSON 
SET OSSPERSON.Firstname = @FIRSTNAME
, OSSPERSON.Lastname=@LASTNAME
, OSSPERSON.AorC=@AorC
, OSSPERSON.Age=@AGE
, OSSPERSON.Gender = @GENDER 
FROM EDUForm.dbo.OSSPERSON INNER JOIN EDUForm.dbo.OSSREGPERSON ON OSSPERSON.PERSONID = OSSREGPERSON.PERSONID 
INNER JOIN EDUForm.dbo.OSSREG ON OSSREGPERSON.REGID = OSSREG.REGID WHERE 
(OSSREG.PERSONID = @PERSONID)" onselecting="SqlDataSource2_Selecting">
                    <SelectParameters>
                    <asp:Parameter Name="guid" Type="String"/>
                        <%--<asp:SessionParameter Name="guid" SessionField="guid" 
                            DefaultValue="" />--%>
                    </SelectParameters>
                    <UpdateParameters>
                    
                        <asp:Parameter Name="PERSONID" Type="Int32" />
                        <asp:Parameter Name="FIRSTNAME" Type="String" />
                        <asp:Parameter Name="LASTNAME" Type="String" />
                        <asp:Parameter Name="AorC" Type="String" />
                        <asp:Parameter Name="AGE" Type="Int16" />
                        <asp:Parameter Name="GENDER" Type="String" />
                        <asp:Parameter Name="guid" Type="String"/>
                    </UpdateParameters>
                </asp:SqlDataSource>
protected void SqlDataSource2_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {
            if (guid != null)
            {
                e.Command.Parameters["@guid"].Value = guid;
            }
        }

Edited by jon4321: n/a

1
Contributor
1
Reply
2
Views
5 Years
Discussion Span
Last Post by jon4321
0

Okay, so I realized I should be updating based on id rather than guid (which in my case would update the whole group instead of just one). I still don't know why the guid wasn't visible to the update statement, but my immediate issue is solved.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.