ASP.net : Listview datakeynames for multiple sql staements in SqlDataSource's update command

ASP.net : Listview datakeynames for multiple sql staements in SqlDataSource's update command
I am using two tables in listview. I have to update both tables simultaneously after update. To do this
1. use multiple sql update statement in sqldatasource update command seperated by ;
2. set datakeys property to primary key of both tables seperated by comma ,

Example:


              <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:entertrackConnectionString %>" 
                        InsertCommand=" INSERT INTO contact_master (uid, eid, cell, email, dept, desig, name, rax, off, resid) values ( @uid, @eid, @cell, @email, @dept, @desig, @name, @rax, @off, @resid ) ;
INSERT INTO contact_detail (eid, assign, field1, uid) values ( @uid, @assign, @field1, @uid )
                        ProviderName="<%$ ConnectionStrings:entertrackConnectionString.ProviderName %>" 
                        SelectCommand="select m.uid, m.eid, m.cell, m.email, m.dept, m.desig, m.name, m.rax, m.off, m.resid , d.eid as eid1, d.assign, d.field1, d.uid as uid1 from contact_detail d Left Outer Join contact_master m on d.eid = m.uid" 
                        
                        UpdateCommand="  UPDATE contact_master SET  eid= @eid, cell= @cell, email= @email, dept= @dept, desig= @desig, name= @name, rax= @rax, off= @off, resid= @resid WHERE uid = @uid ;
                        UPDATE contact_detail SET  eid= @uid, assign= @assign, field1= @field1 WHERE uid = @uid1  " 
                        >



 <UpdateParameters>
                         <asp:Parameter Name="uid" Type="Int32" />
                            <asp:Parameter Name="eid" Type="String" />
                            <asp:Parameter Name="cell" Type="String" />
                            <asp:Parameter Name="email" Type="String" />
                            <asp:Parameter Name="dept" Type="String" />
                            <asp:Parameter Name="desig" Type="String" />
                            <asp:Parameter Name="name" Type="String" />
                            <asp:Parameter Name="rax" Type="String" />
                            <asp:Parameter Name="off" Type="String" />
                            <asp:Parameter Name="resid" Type="String" />
                           
                            
                              <asp:Parameter Name="eid1" Type="String" />
                            <asp:Parameter Name="assign" Type="String" />
                            <asp:Parameter Name="field1" Type="String" />
                            <asp:Parameter Name="uid1" Type="Int32" />
                        </UpdateParameters>





</asp:SqlDataSource>


   
                    <asp:ListView ID="ListView1" runat="server" DataKeyNames="uid, uid1" 
                        DataSourceID="SqlDataSource1" InsertItemPosition="LastItem">






Thus you would be able to update in both tables from single list view. Same can be done for insert command using scope_identity.
- Vinod Kotiya
www.vinodkotiya.com

Comments