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;
            }
        }

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.