使用SqlDataSource删除空字典错误 – ASP.net ListView
发布时间:2020-12-16 06:21:57 所属栏目:asp.Net 来源:网络整理
导读:我正在尝试使用乐观并发创建一个简单的ListView.它使用VS自动生成的Delete,Insert,Update语句(除了1更改插入:参见代码). ?插入和编辑工作正常并提交到数据库.尝试删除时,我收到此错误: 您已指定delete命令比较SqlDataSource’MySourceHere’上的所有值,但
我正在尝试使用乐观并发创建一个简单的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> 解决方法
在我的ItemTemplate / AlternatingItemTemplate(就像编辑模板)中更改非主键字段以使用“绑定”而不是“Eval”显然需要正确传递旧值.
这是一个使用自动生成的标记而没有完全理解它的情况(我仍然没有,真的.) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 白话ASP.NET MVC之三:Controller是如何解析出来的
- asp.net-mvc – 如何在剃刀中获取页面原点?
- asp.net-mvc – 如何在发布MVC应用程序时包含自定义文件夹?
- ASP.NET和Web Tools 2012.2引用LESS文件
- asp.net-mvc – 为什么我在MVC3控制器中的模型中更新的值没
- asp.net – 服务应用程序池“X”的进程与Windows进程激活服
- asp.net – 如何在不依赖其扩展名的情况下检查上传文件的内
- asp.net-mvc – 如何单元测试MSTest中的JsonResult和集合
- ASP.NET核心中的Redis缓存
- 在ASP.NET中实现404的最佳方式
推荐文章
站长推荐
- asp.net-mvc – ASP.NET MVC:使用没有IClientVa
- asp.net-core – 在.NET Core Web API上为CORS启
- asp.net-mvc – 如何将ms显示从LHS移动到RHS
- AspNetCore MVC页面数据提交验证
- asp.net-mvc – Spark VS 2010 intellisense
- asp.net-mvc-3 – mvc3剃刀条件包装器div
- asp.net – 内存转储不显示IIS崩溃的详细信息
- .net – 扩展/插件通信的体系结构
- asp.net – 无法加载mysql.web程序集
- System.Net.ServicePointManager.DefaultConnect
热点阅读