Insert和Delete Query在AccessDataSource中停止工作

时间:2011-08-10 21:03:13

标签: asp.net database ms-access

我有一个提交按钮,可以将用户输入的数据插入数据库。在将项目迁移到主机服务器之前,它工作正常。选择查询仍然有效并在GridView中显示我的数据(我通过手动将一些数据插入主机服务器上的数据库来检查),我无法通过客户端页面插入或删除数据。它是一个访问数据库,我使用Visual Studio AccessDataSource连接到它。

另外,我在加载页面时没有收到任何错误,或者当我点击提交时,它只是没有任何反应。

这是我的代码:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="jotest.aspx.vb" Inherits="jotest" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script language="javascript" type="text/javascript">
<!--
            function imposeMaxLength(Object, MaxLen) {
                return (Object.value.length <= MaxLen);
            }
-->
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/login.mdb" 
DeleteCommand="DELETE FROM tblComments WHERE ID = @ID" 
InsertCommand="INSERT INTO tblComments(comment, commentor_name, comment_date) VALUES (@comment, @commentor_name, @comment_date)" 
 SelectCommand="SELECT ID, commentor_name, comment, comment_date FROM tblComments">
<InsertParameters>
<asp:Parameter Name="commentor_name" />
<asp:Parameter Name="comment" />
<asp:Parameter Name="comment_date" />
<asp:Parameter Name="ID" />
</InsertParameters>
<DeleteParameters>
<asp:Parameter Name="ID" />
</DeleteParameters>
</asp:AccessDataSource>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div style="position: absolute; top: 50px; left: 600px;">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="AccessDataSource1" CellPadding="4" ForeColor="#333333" GridLines="None" AllowSorting="True">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="comment" HeaderText="Name" SortExpression="comment" ItemStyle-Width="80px" />
<asp:BoundField DataField="commentor_name" HeaderText="Comment" SortExpression="commentor_name" ItemStyle-Width="300px" />
<asp:BoundField DataField="comment_date" HeaderText="Date" SortExpression="date" ItemStyle-Width="175px" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
</div>
<br />
<asp:FormView ID="FormView1" runat="server" DataSourceID="AccessDataSource1" DefaultMode="Insert">
<InsertItemTemplate>
Name:<asp:TextBox ID="commentor_nameTextBox" runat="server" Text='<%# Bind("commentor_name") %>'></asp:TextBox>
<br />
Comment:<asp:TextBox ID="txtComments" runat="server" onkeypress="return imposeMaxLength(this, 150);" Text='<%# Bind("comment") %>' TextMode="MultiLine" Rows="4" Columns="50"></asp:TextBox>
<br />
<asp:HiddenField ID="hidTimeDate" runat="server" Value='<%# Bind("comment_date") %>' />
<asp:Button ID="butSubmit" runat="server" CommandName="Insert" Text="Submit" />
</InsertItemTemplate>
</asp:FormView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

确保访问该文件的帐户对mdb文件所在的主机服务器文件夹具有读写访问权限。