W
webby
I have created a ASP script using Microsoft Visual Web Developer Express
Edition 2005 that will enable users to edit a Access database in a gridview.
The script functions without any errors and allows you to edit the fields but
when you press the update button the page refreshes and the changes are lost.
I have triple checked the perms n(IUSR and IWAM) on the access db, the aspx
page and the folders and they appear correct. This is running on Windows XP
Pro with IIS for dev purposes only, after it workes correctly I will transfer
it to W2003 Server. Here is the code:
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="AutoNumber" DataSourceID="AccessDataSource7"
ForeColor="#333333"
GridLines="None" Height="216px" Style="z-index: 100; left: 10px;
position: absolute;
top: 121px" Width="359px">
<FooterStyle BackColor="#507CD1" Font-Bold="True"
ForeColor="White" />
<Columns>
<asp:CommandField ShowDeleteButton="True"
ShowEditButton="True" ShowSelectButton="True" />
<asp:BoundField DataField="AutoNumber"
HeaderText="AutoNumber" InsertVisible="False"
ReadOnly="True" SortExpression="AutoNumber" />
<asp:BoundField DataField="LastName" HeaderText="LastName"
SortExpression="LastName" />
<asp:BoundField DataField="Soundex" HeaderText="Soundex"
SortExpression="Soundex" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName"
SortExpression="FirstName" />
<asp:BoundField DataField="MiddleInitial"
HeaderText="MiddleInitial" SortExpression="MiddleInitial" />
<asp:BoundField DataField="CaseNumber"
HeaderText="CaseNumber" SortExpression="CaseNumber" />
<asp:BoundField DataField="DOB" HeaderText="DOB"
SortExpression="DOB" />
<asp:BoundField DataField="Race" HeaderText="Race"
SortExpression="Race" />
<asp:BoundField DataField="Sex" HeaderText="Sex"
SortExpression="Sex" />
<asp:BoundField DataField="Address" HeaderText="Address"
SortExpression="Address" />
<asp:CheckBoxField DataField="PublicHousing"
HeaderText="PublicHousing" SortExpression="PublicHousing" />
<asp:BoundField DataField="Date" HeaderText="Date"
SortExpression="Date" />
<asp:BoundField DataField="Length" HeaderText="Length"
SortExpression="Length" />
<asp:BoundField DataField="EmpLastName"
HeaderText="EmpLastName" SortExpression="EmpLastName" />
<asp:BoundField DataField="EmpfirstName"
HeaderText="EmpfirstName" SortExpression="EmpfirstName" />
</Columns>
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True"
ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True"
ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource7" runat="server"
ConflictDetection="CompareAllValues"
DataFile="C:\Inetpub\wwwroot\db\VBTEST.mdb"
DeleteCommand="DELETE FROM [Trespass] WHERE [AutoNumber] = ? AND [LastName] =
? AND [Soundex] = ? AND [FirstName] = ? AND [MiddleInitial] = ? AND
[CaseNumber] = ? AND [DOB] = ? AND [Race] = ? AND [Sex] = ? AND [Address] = ?
AND [PublicHousing] = ? AND [Date] = ? AND [Length] = ? AND [EmpLastName] = ?
AND [EmpfirstName] = ?"
InsertCommand="INSERT INTO [Trespass] ([AutoNumber], [LastName],
[Soundex], [FirstName], [MiddleInitial], [CaseNumber], [DOB], [Race], [Sex],
[Address], [PublicHousing], [Date], [Length], [EmpLastName], [EmpfirstName])
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT * FROM [Trespass]"
UpdateCommand="UPDATE [Trespass] SET [LastName] = ?, [Soundex] =
?, [FirstName] = ?, [MiddleInitial] = ?, [CaseNumber] = ?, [DOB] = ?, [Race]
= ?, [Sex] = ?, [Address] = ?, [PublicHousing] = ?, [Date] = ?, [Length] = ?,
[EmpLastName] = ?, [EmpfirstName] = ? WHERE [AutoNumber] = ? AND [LastName] =
? AND [Soundex] = ? AND [FirstName] = ? AND [MiddleInitial] = ? AND
[CaseNumber] = ? AND [DOB] = ? AND [Race] = ? AND [Sex] = ? AND [Address] = ?
AND [PublicHousing] = ? AND [Date] = ? AND [Length] = ? AND [EmpLastName] = ?
AND [EmpfirstName] = ?">
<DeleteParameters>
<asparameter Name="original_AutoNumber" Type="Int32" />
<asparameter Name="original_LastName" Type="String" />
<asparameter Name="original_Soundex" Type="String" />
<asparameter Name="original_FirstName" Type="String" />
<asparameter Name="original_MiddleInitial" Type="String" />
<asparameter Name="original_CaseNumber" Type="Int32" />
<asparameter Name="original_DOB" Type="String" />
<asparameter Name="original_Race" Type="String" />
<asparameter Name="original_Sex" Type="String" />
<asparameter Name="original_Address" Type="String" />
<asparameter Name="original_PublicHousing" Type="Boolean" />
<asparameter Name="original_Date" Type="DateTime" />
<asparameter Name="original_Length" Type="String" />
<asparameter Name="original_EmpLastName" Type="String" />
<asparameter Name="original_EmpfirstName" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asparameter Name="LastName" Type="String" />
<asparameter Name="Soundex" Type="String" />
<asparameter Name="FirstName" Type="String" />
<asparameter Name="MiddleInitial" Type="String" />
<asparameter Name="CaseNumber" Type="Int32" />
<asparameter Name="DOB" Type="String" />
<asparameter Name="Race" Type="String" />
<asparameter Name="Sex" Type="String" />
<asparameter Name="Address" Type="String" />
<asparameter Name="PublicHousing" Type="Boolean" />
<asparameter Name="Date" Type="DateTime" />
<asparameter Name="Length" Type="String" />
<asparameter Name="EmpLastName" Type="String" />
<asparameter Name="EmpfirstName" Type="String" />
<asparameter Name="original_AutoNumber" Type="Int32" />
<asparameter Name="original_LastName" Type="String" />
<asparameter Name="original_Soundex" Type="String" />
<asparameter Name="original_FirstName" Type="String" />
<asparameter Name="original_MiddleInitial" Type="String" />
<asparameter Name="original_CaseNumber" Type="Int32" />
<asparameter Name="original_DOB" Type="String" />
<asparameter Name="original_Race" Type="String" />
<asparameter Name="original_Sex" Type="String" />
<asparameter Name="original_Address" Type="String" />
<asparameter Name="original_PublicHousing" Type="Boolean" />
<asparameter Name="original_Date" Type="DateTime" />
<asparameter Name="original_Length" Type="String" />
<asparameter Name="original_EmpLastName" Type="String" />
<asparameter Name="original_EmpfirstName" Type="String" />
</UpdateParameters>
<InsertParameters>
<asparameter Name="AutoNumber" Type="Int32" />
<asparameter Name="LastName" Type="String" />
<asparameter Name="Soundex" Type="String" />
<asparameter Name="FirstName" Type="String" />
<asparameter Name="MiddleInitial" Type="String" />
<asparameter Name="CaseNumber" Type="Int32" />
<asparameter Name="DOB" Type="String" />
<asparameter Name="Race" Type="String" />
<asparameter Name="Sex" Type="String" />
<asparameter Name="Address" Type="String" />
<asparameter Name="PublicHousing" Type="Boolean" />
<asparameter Name="Date" Type="DateTime" />
<asparameter Name="Length" Type="String" />
<asparameter Name="EmpLastName" Type="String" />
<asparameter Name="EmpfirstName" Type="String" />
</InsertParameters>
</asp:AccessDataSource>
</div>
</form>
</body>
</html>
Any help with this would be great. Thanks.
Edition 2005 that will enable users to edit a Access database in a gridview.
The script functions without any errors and allows you to edit the fields but
when you press the update button the page refreshes and the changes are lost.
I have triple checked the perms n(IUSR and IWAM) on the access db, the aspx
page and the folders and they appear correct. This is running on Windows XP
Pro with IIS for dev purposes only, after it workes correctly I will transfer
it to W2003 Server. Here is the code:
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="AutoNumber" DataSourceID="AccessDataSource7"
ForeColor="#333333"
GridLines="None" Height="216px" Style="z-index: 100; left: 10px;
position: absolute;
top: 121px" Width="359px">
<FooterStyle BackColor="#507CD1" Font-Bold="True"
ForeColor="White" />
<Columns>
<asp:CommandField ShowDeleteButton="True"
ShowEditButton="True" ShowSelectButton="True" />
<asp:BoundField DataField="AutoNumber"
HeaderText="AutoNumber" InsertVisible="False"
ReadOnly="True" SortExpression="AutoNumber" />
<asp:BoundField DataField="LastName" HeaderText="LastName"
SortExpression="LastName" />
<asp:BoundField DataField="Soundex" HeaderText="Soundex"
SortExpression="Soundex" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName"
SortExpression="FirstName" />
<asp:BoundField DataField="MiddleInitial"
HeaderText="MiddleInitial" SortExpression="MiddleInitial" />
<asp:BoundField DataField="CaseNumber"
HeaderText="CaseNumber" SortExpression="CaseNumber" />
<asp:BoundField DataField="DOB" HeaderText="DOB"
SortExpression="DOB" />
<asp:BoundField DataField="Race" HeaderText="Race"
SortExpression="Race" />
<asp:BoundField DataField="Sex" HeaderText="Sex"
SortExpression="Sex" />
<asp:BoundField DataField="Address" HeaderText="Address"
SortExpression="Address" />
<asp:CheckBoxField DataField="PublicHousing"
HeaderText="PublicHousing" SortExpression="PublicHousing" />
<asp:BoundField DataField="Date" HeaderText="Date"
SortExpression="Date" />
<asp:BoundField DataField="Length" HeaderText="Length"
SortExpression="Length" />
<asp:BoundField DataField="EmpLastName"
HeaderText="EmpLastName" SortExpression="EmpLastName" />
<asp:BoundField DataField="EmpfirstName"
HeaderText="EmpfirstName" SortExpression="EmpfirstName" />
</Columns>
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True"
ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True"
ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource7" runat="server"
ConflictDetection="CompareAllValues"
DataFile="C:\Inetpub\wwwroot\db\VBTEST.mdb"
DeleteCommand="DELETE FROM [Trespass] WHERE [AutoNumber] = ? AND [LastName] =
? AND [Soundex] = ? AND [FirstName] = ? AND [MiddleInitial] = ? AND
[CaseNumber] = ? AND [DOB] = ? AND [Race] = ? AND [Sex] = ? AND [Address] = ?
AND [PublicHousing] = ? AND [Date] = ? AND [Length] = ? AND [EmpLastName] = ?
AND [EmpfirstName] = ?"
InsertCommand="INSERT INTO [Trespass] ([AutoNumber], [LastName],
[Soundex], [FirstName], [MiddleInitial], [CaseNumber], [DOB], [Race], [Sex],
[Address], [PublicHousing], [Date], [Length], [EmpLastName], [EmpfirstName])
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT * FROM [Trespass]"
UpdateCommand="UPDATE [Trespass] SET [LastName] = ?, [Soundex] =
?, [FirstName] = ?, [MiddleInitial] = ?, [CaseNumber] = ?, [DOB] = ?, [Race]
= ?, [Sex] = ?, [Address] = ?, [PublicHousing] = ?, [Date] = ?, [Length] = ?,
[EmpLastName] = ?, [EmpfirstName] = ? WHERE [AutoNumber] = ? AND [LastName] =
? AND [Soundex] = ? AND [FirstName] = ? AND [MiddleInitial] = ? AND
[CaseNumber] = ? AND [DOB] = ? AND [Race] = ? AND [Sex] = ? AND [Address] = ?
AND [PublicHousing] = ? AND [Date] = ? AND [Length] = ? AND [EmpLastName] = ?
AND [EmpfirstName] = ?">
<DeleteParameters>
<asparameter Name="original_AutoNumber" Type="Int32" />
<asparameter Name="original_LastName" Type="String" />
<asparameter Name="original_Soundex" Type="String" />
<asparameter Name="original_FirstName" Type="String" />
<asparameter Name="original_MiddleInitial" Type="String" />
<asparameter Name="original_CaseNumber" Type="Int32" />
<asparameter Name="original_DOB" Type="String" />
<asparameter Name="original_Race" Type="String" />
<asparameter Name="original_Sex" Type="String" />
<asparameter Name="original_Address" Type="String" />
<asparameter Name="original_PublicHousing" Type="Boolean" />
<asparameter Name="original_Date" Type="DateTime" />
<asparameter Name="original_Length" Type="String" />
<asparameter Name="original_EmpLastName" Type="String" />
<asparameter Name="original_EmpfirstName" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asparameter Name="LastName" Type="String" />
<asparameter Name="Soundex" Type="String" />
<asparameter Name="FirstName" Type="String" />
<asparameter Name="MiddleInitial" Type="String" />
<asparameter Name="CaseNumber" Type="Int32" />
<asparameter Name="DOB" Type="String" />
<asparameter Name="Race" Type="String" />
<asparameter Name="Sex" Type="String" />
<asparameter Name="Address" Type="String" />
<asparameter Name="PublicHousing" Type="Boolean" />
<asparameter Name="Date" Type="DateTime" />
<asparameter Name="Length" Type="String" />
<asparameter Name="EmpLastName" Type="String" />
<asparameter Name="EmpfirstName" Type="String" />
<asparameter Name="original_AutoNumber" Type="Int32" />
<asparameter Name="original_LastName" Type="String" />
<asparameter Name="original_Soundex" Type="String" />
<asparameter Name="original_FirstName" Type="String" />
<asparameter Name="original_MiddleInitial" Type="String" />
<asparameter Name="original_CaseNumber" Type="Int32" />
<asparameter Name="original_DOB" Type="String" />
<asparameter Name="original_Race" Type="String" />
<asparameter Name="original_Sex" Type="String" />
<asparameter Name="original_Address" Type="String" />
<asparameter Name="original_PublicHousing" Type="Boolean" />
<asparameter Name="original_Date" Type="DateTime" />
<asparameter Name="original_Length" Type="String" />
<asparameter Name="original_EmpLastName" Type="String" />
<asparameter Name="original_EmpfirstName" Type="String" />
</UpdateParameters>
<InsertParameters>
<asparameter Name="AutoNumber" Type="Int32" />
<asparameter Name="LastName" Type="String" />
<asparameter Name="Soundex" Type="String" />
<asparameter Name="FirstName" Type="String" />
<asparameter Name="MiddleInitial" Type="String" />
<asparameter Name="CaseNumber" Type="Int32" />
<asparameter Name="DOB" Type="String" />
<asparameter Name="Race" Type="String" />
<asparameter Name="Sex" Type="String" />
<asparameter Name="Address" Type="String" />
<asparameter Name="PublicHousing" Type="Boolean" />
<asparameter Name="Date" Type="DateTime" />
<asparameter Name="Length" Type="String" />
<asparameter Name="EmpLastName" Type="String" />
<asparameter Name="EmpfirstName" Type="String" />
</InsertParameters>
</asp:AccessDataSource>
</div>
</form>
</body>
</html>
Any help with this would be great. Thanks.