我在asp.net项目中使用UPDATE命令时遇到问题。该项目允许用户通过登录页面登录,该登录页面将用户名和密码与数据库中的记录相匹配,并将用户名保存为cookie。然后我有一个设置页面,我想让用户编辑他们的帐户详细信息,但是当我使用UPDATE函数时,执行查询没有任何错误,但不会发生更新。我正在使用AccessDataSource和UpdateCommand,希望有人可以找到我的代码的问题,并指导我正确的方向。 提前致谢
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim sqlcmd As String
sqlcmd = "SELECT FirstName, SecondName, UserName, DOB, Password FROM UserTable WHERE UserName = '" & Request.Cookies("UserInfo")("userName") & "'"
AccessDataSource1.SelectCommand = sqlcmd
If (Not Page.IsPostBack) Then
Dim sqlcmd2 As String
sqlcmd2 = "UPDATE [UserTable] SET [FirstName] = ?, [SecondName] = ?, [UserName] = ?, [DOB] = ?, [Password] = ? WHERE [UserID] = ? AND ISNULL (([FirstName] = ?) OR ([FirstName] IS NULL AND ? IS NULL)) AND (([SecondName] = ?) OR ([SecondName] IS NULL AND ? IS NULL)) AND (([UserName] = ?) OR ([UserName] IS NULL AND ? IS NULL)) AND (([DOB] = ?) OR ([DOB] IS NULL AND ? IS NULL)) AND (([Password] = ?) OR ([Password] IS NULL AND ? IS NULL))"
AccessDataSource1.UpdateCommand = sqlcmd2
End If
End Sub
<form id="webform" runat="server">
<div id="content">
<asp:AccessDataSource ID="AccessDataSource1" DataSourceMode = "DataSet" runat="server"
ConflictDetection="CompareAllValues" DataFile="~/Database.mdb"
OldValuesParameterFormatString="original_{0}"
UpdateCommand = "UPDATE [UserTable] SET [FirstName] = ?, [SecondName] = ?, [UserName] = ?, [DOB] = ?, [Password] = ? WHERE [UserID] = ? AND ISNULL (([FirstName] = ?) OR ([FirstName] IS NULL AND ? IS NULL)) AND (([SecondName] = ?) OR ([SecondName] IS NULL AND ? IS NULL)) AND (([UserName] = ?) OR ([UserName] IS NULL AND ? IS NULL)) AND (([DOB] = ?) OR ([DOB] IS NULL AND ? IS NULL)) AND (([Password] = ?) OR ([Password] IS NULL AND ? IS NULL))">
<UpdateParameters>
<asp:Parameter Name="UserID" Type="Int32" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="SecondName" Type="String" />
<asp:Parameter Name="UserName" Type="String" />
<asp:Parameter Name="DOB" Type="String" />
<asp:Parameter Name="Password" Type="String" />
<asp:Parameter Name="original_UserID" Type="Int32" />
<asp:Parameter Name="original_FirstName" Type="String" />
<asp:Parameter Name="original_FirstName" Type="String" />
<asp:Parameter Name="original_SecondName" Type="String" />
<asp:Parameter Name="original_SecondName" Type="String" />
<asp:Parameter Name="original_UserName" Type="String" />
<asp:Parameter Name="original_UserName" Type="String" />
<asp:Parameter Name="original_DOB" Type="String" />
<asp:Parameter Name="original_DOB" Type="String" />
<asp:Parameter Name="original_Password" Type="String" />
<asp:Parameter Name="original_Password" Type="String" />
</UpdateParameters>
</asp:AccessDataSource>
<asp:GridView ID="GridView1" runat="server" DataSourceID="AccessDataSource1">
<Columns>
<asp:CommandField ShowEditButton="True" />
</Columns>
</asp:GridView>
<div>
</div>
</div>
</form>
对不起,如果它有点乱,但这是我的第一篇文章,我不完全确定我在做什么。
答案 0 :(得分:0)
尝试添加
accessdatasource1.update()