我正在尝试使用乐观并发创建一个简单的ListView.它使用VS自动生成的Delete,Insert,Update语句(除了1更改插入:参见代码).
插入和编辑工作正常并提交到数据库.尝试删除时,我收到此错误:
插入和编辑工作正常并提交到数据库.尝试删除时,我收到此错误:
您已指定delete命令比较sqlDataSource’MySourceHere’上的所有值,但传入值的字典为空.传入有效字典进行删除或将模式更改为OverwriteChanges.
我曾尝试将“CompareAllValues”更改为“OverwriteChanges”以推迟并发工作,但是“中断”更新和删除命令,这似乎是用旧值刷新ListView.我能找到解决此问题的唯一线程涉及更改为“OverwriteChanges”,或者是没有声明“DataKeyNames”的人. Relevent标记低于(我希望).
有什么想法吗?
<asp:sqlDataSource ID="ManageUseRSSource" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ConnectionStrings:ConnectionString %>" DeleteCommand="DELETE FROM [DUSER] WHERE [userid] = ? AND (([username] = ?) OR ([username] IS NULL AND ? IS NULL)) AND (([userpass] = ?) OR ([userpass] IS NULL AND ? IS NULL))" InsertCommand="INSERT INTO [DUSER] ([username],[userpass]) VALUES (?,?)" OldValuesParameterFormatString="original_{0}" ProviderName="<%$ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [DUSER] ORDER BY [userid] ASC" UpdateCommand="UPDATE [DUSER] SET [username] = ?,[userpass] = ? WHERE [userid] = ? AND (([username] = ?) OR ([username] IS NULL AND ? IS NULL)) AND (([userpass] = ?) OR ([userpass] IS NULL AND ? IS NULL))"> <DeleteParameters> <asp:Parameter Name="original_userid" Type="Int16" /> <asp:Parameter Name="original_username" Type="String" /> <asp:Parameter Name="original_username" Type="String" /> <asp:Parameter Name="original_userpass" Type="String" /> <asp:Parameter Name="original_userpass" Type="String" /> </DeleteParameters> <InsertParameters> <%--This is removed since [userid] is an automatically generated index.--%> <%--<asp:Parameter Name="userid" Type="Int16" />--%> <asp:Parameter Name="username" Type="String" /> <asp:Parameter Name="userpass" Type="String" /> </InsertParameters> <UpdateParameters> <asp:Parameter Name="username" Type="String" /> <asp:Parameter Name="userpass" Type="String" /> <asp:Parameter Name="original_userid" Type="Int16" /> <asp:Parameter Name="original_username" Type="String" /> <asp:Parameter Name="original_username" Type="String" /> <asp:Parameter Name="original_userpass" Type="String" /> <asp:Parameter Name="original_userpass" Type="String" /> </UpdateParameters> </asp:sqlDataSource> <asp:ListView ID="ListView1" runat="server" DataKeyNames="userid" DataSourceID="ManageUseRSSource" InsertItemPosition="LastItem"> <AlternatingItemTemplate> <tr style="background-color:#FFF8DC;"> <td> <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" /> <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" /> </td> <td> <asp:Label ID="useridLabel" runat="server" Text='<%# Eval("userid") %>' /> </td> <td> <asp:Label ID="usernameLabel" runat="server" Text='<%# Eval("username") %>' /> </td> <td> <asp:Label ID="userpassLabel" runat="server" Text='<%# Eval("userpass") %>' /> </td> </tr> </AlternatingItemTemplate> <EditItemTemplate> <tr style="background-color:#008A8C;color: #FFFFFF;"> <td> <asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" /> <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" /> </td> <td> <asp:Label ID="useridLabel1" runat="server" Text='<%# Eval("userid") %>' /> </td> <td> <asp:TextBox ID="usernameTextBox" runat="server" Text='<%# Bind("username") %>' /> </td> <td> <asp:TextBox ID="userpasstextBox" runat="server" Text='<%# Bind("userpass") %>' /> </td> </tr> </EditItemTemplate> <EmptyDataTemplate> <table runat="server" style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;"> <tr> <td> No data was returned.</td> </tr> </table> </EmptyDataTemplate> <InsertItemTemplate> <tr style=""> <td> <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" /> <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" /> </td> <td> </td> <td> <asp:TextBox ID="usernameTextBox" runat="server" Text='<%# Bind("username") %>' /> </td> <td> <asp:TextBox ID="userpasstextBox" runat="server" Text='<%# Bind("userpass") %>' /> </td> </tr> </InsertItemTemplate> <ItemTemplate> <tr style="background-color:#DCDCDC;color: #000000;"> <td> <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" /> <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" /> </td> <td> <asp:Label ID="useridLabel" runat="server" Text='<%# Eval("userid") %>' /> </td> <td> <asp:Label ID="usernameLabel" runat="server" Text='<%# Eval("username") %>' /> </td> <td> <asp:Label ID="userpassLabel" runat="server" Text='<%# Eval("userpass") %>' /> </td> </tr> </ItemTemplate> <LayoutTemplate> <table runat="server"> <tr runat="server"> <td runat="server"> <table ID="itemPlaceholderContainer" runat="server" border="1" style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana,Arial,Helvetica,sans-serif;"> <tr runat="server" style="background-color:#DCDCDC;color: #000000;"> <th runat="server"> </th> <th runat="server"> userid</th> <th runat="server"> username</th> <th runat="server"> userpass</th> </tr> <tr ID="itemPlaceholder" runat="server"> </tr> </table> </td> </tr> <tr runat="server"> <td runat="server" style="text-align: center;background-color: #CCCCCC;font-family: Verdana,sans-serif;color: #000000;"> <asp:DataPager ID="DataPager1" runat="server"> <Fields> <asp:NextPrevIoUsPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" /> </Fields> </asp:DataPager> </td> </tr> </table> </LayoutTemplate> <SelectedItemTemplate> <tr style="background-color:#008A8C;font-weight: bold;color: #FFFFFF;"> <td> <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" /> <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" /> </td> <td> <asp:Label ID="useridLabel" runat="server" Text='<%# Eval("userid") %>' /> </td> <td> <asp:Label ID="usernameLabel" runat="server" Text='<%# Eval("username") %>' /> </td> <td> <asp:Label ID="userpassLabel" runat="server" Text='<%# Eval("userpass") %>' /> </td> </tr> </SelectedItemTemplate> </asp:ListView>
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。