Link to home
Start Free TrialLog in
Avatar of Carsontl
Carsontl

asked on

Access database is not updating, please help!

Hello everyone,

I'm trying to get my access database to update via an asp .net site.  I'm using Visual Web studio 2008 to create everything, and after a couple weeks of research I've been able to set it up how i like it.  The only problem is that Edit/Insert/ and Delete are not working properly.

Thinking it was a permissions error i went through and made sure all the accounts have write capability.

Can anyone help?
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
 
<!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>
    <style type="text/css">
        #form1
        {
            width: 389px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
        DataFile="~/App_Data/Assets.mdb" 
        SelectCommand="SELECT * FROM [Assets]" 
        DeleteCommand="DELETE FROM [Assets] WHERE [ID] = ?" 
        InsertCommand="INSERT INTO [Assets] ([ID], [Host Name], [Owner], [Manufacturer], [Model], [OS], [CPU], [Memory], [HD Capacity], [Comments], [Picture]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" 
        UpdateCommand="UPDATE [Assets] SET [Host Name] = ?, [Owner] = ?, [Manufacturer] = ?, [Model] = ?, [OS] = ?, [CPU] = ?, [Memory] = ?, [HD Capacity] = ?, [Comments] = ?, [Picture] = ? WHERE [ID] = ?">
        <DeleteParameters>
            <asp:Parameter Name="ID" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="Host_Name" Type="String" />
            <asp:Parameter Name="Owner" Type="String" />
            <asp:Parameter Name="Manufacturer" Type="String" />
            <asp:Parameter Name="Model" Type="String" />
            <asp:Parameter Name="OS" Type="String" />
            <asp:Parameter Name="CPU" Type="String" />
            <asp:Parameter Name="Memory" Type="String" />
            <asp:Parameter Name="HD_Capacity" Type="String" />
            <asp:Parameter Name="Comments" Type="String" />
            <asp:Parameter Name="Picture" Type="String" />
            <asp:Parameter Name="ID" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="ID" Type="Int32" />
            <asp:Parameter Name="Host_Name" Type="String" />
            <asp:Parameter Name="Owner" Type="String" />
            <asp:Parameter Name="Manufacturer" Type="String" />
            <asp:Parameter Name="Model" Type="String" />
            <asp:Parameter Name="OS" Type="String" />
            <asp:Parameter Name="CPU" Type="String" />
            <asp:Parameter Name="Memory" Type="String" />
            <asp:Parameter Name="HD_Capacity" Type="String" />
            <asp:Parameter Name="Comments" Type="String" />
            <asp:Parameter Name="Picture" Type="String" />
        </InsertParameters>
    </asp:AccessDataSource>
    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
        CellPadding="4" DataSourceID="AccessDataSource1" ForeColor="#333333" 
        GridLines="None" Height="50px" Width="223px" DataKeyNames="ID" 
        AllowPaging="True">
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <Fields>
            <asp:BoundField DataField="Host Name" HeaderText="Host Name" 
                SortExpression="Host Name" />
            <asp:BoundField DataField="Owner" HeaderText="Owner" SortExpression="Owner" />
            <asp:BoundField DataField="Manufacturer" HeaderText="Manufacturer" 
                SortExpression="Manufacturer" />
            <asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" />
            <asp:BoundField DataField="OS" HeaderText="OS" SortExpression="OS" />
            <asp:BoundField DataField="CPU" HeaderText="CPU" SortExpression="CPU" />
            <asp:BoundField DataField="Memory" HeaderText="Memory" 
                SortExpression="Memory" />
            <asp:BoundField DataField="HD Capacity" HeaderText="HD Capacity" 
                SortExpression="HD Capacity" />
            <asp:BoundField DataField="Comments" HeaderText="Comments" 
                SortExpression="Comments" />
            <asp:BoundField DataField="Picture" HeaderText="Picture" 
                SortExpression="Picture" />
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
                ShowInsertButton="True" />
        </Fields>
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#999999" />
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:DetailsView>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    
    </form>
    
 
 
</body>
</html>

Open in new window

Avatar of OMC2000
OMC2000
Flag of Russian Federation image

accounts must have write capability for the folder where MDB file is located. It is necessary for ldb file creation.
Avatar of Carsontl
Carsontl

ASKER

I've confirmed that the accounts have write capability.
What error message are you getting when you click insert, for example?
When i click Delete, it works
When i click Edit, the page refreshes after i submit it and nothing changes
When i click Insert, the page returns:


Server Error in '/Sysinfo' Application.
--------------------------------------------------------------------------------
 
You tried to assign the Null value to a variable that is not a Variant data type. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
 
Exception Details: System.Data.OleDb.OleDbException: You tried to assign the Null value to a variable that is not a Variant data type.
 
Source Error: 
 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  
 
Stack Trace: 
 
 
[OleDbException (0x80004005): You tried to assign the Null value to a variable that is not a Variant data type.]
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) +1002416
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +255
   System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +188
   System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +58
   System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +161
   System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +113
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +386
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteInsert(IDictionary values) +227
   System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) +86
   System.Web.UI.WebControls.DetailsView.HandleInsert(String commandArg, Boolean causesValidation) +274
   System.Web.UI.WebControls.DetailsView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +676
   System.Web.UI.WebControls.DetailsView.OnBubbleEvent(Object source, EventArgs e) +95
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.DetailsViewRow.OnBubbleEvent(Object source, EventArgs e) +113
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +118
   System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +135
   System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
 
 
 
 
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053 

Open in new window

The only thing that's frustrating is i'm not assigning null values to any of the fields.
There is no binding for ID field. it is key field and you should either let user assign value to it in some control or you should make it autonumber and exclude it from the list of parameters.
When no value assigned to variable it has NULL value and when you pass it into underlying code, which performs insert that NULL is assigning to some variable
The database already has it set up as an autonumber, do i have to specify it as an auto number on the page as well?  If so what would i have to add?

Thanks for your help so far OMC2000!
if it is already autonumber in the database then you should only remove ID from INSERT parameters list
Thank you very much, that resolved the Insert problems.

Updating is still an issue, any ideas?
Well, i fixed this problem by replacing space with underscore symbol in the names of the fields in the database. Actually insert didn't work for the fields "Host name" & "HD Capacity" too.
Just  rename these fields with "Host_name" & "HD_Capacity"  in the database and replace all occurences of these words in source code with new names
Thanks i changed the fields,

I came up with a solution, I've set up a default page to load by querystring to display by owner, set up a button that links to an editor, and created a secondary page, editor.aspx that houses all the functions for manipulating the database.

I added a drop down menu, bound it to a secondary access source, set it to return the ID value with auto postback, and set the details view to display via the ID value.  The issue i've ran into is the drop down menu doesn't update itself after i've inserted a new row. I checked the database and the new rows are inserted just fine but i have to rebuild the site in order to get the drop down menu to populate the new rows... is there an easier way?

If i should make a new 'help ticket' on EE i can do that, i do appreciate all your help!
I'm not sure I understand this new issue, it's always better to see code for such a question...
1. When i insert a new record into the DB it works perfectly, i can open the DB and see it in Access.
2. The new record does not show up in the drop down menu.
3. This is the editor page, i have a link to it from the default.aspx to open this editor.  If i go back to default.aspx and open the editor again, the new record is displayed, but not until i do that.

Bottom line - the drop down menu doesn't update after i've added a new record or deleted one.

Any ideas?

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Editor.aspx.vb" Inherits="_Default" %>
 
<!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>
</head>
<body>
    <form id="form1" runat="server">
    <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
        DataFile="~/App_Data/Assets.mdb" 
        DeleteCommand="DELETE FROM [Assets] WHERE [ID] = ?" 
        InsertCommand="INSERT INTO [Assets] ([Host_Name], [Owner], [Manufacturer], [Model], [OS], [CPU], [Memory], [HD_Capacity], [Comments], [Picture]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" 
        SelectCommand="SELECT * FROM [Assets] WHERE ([ID] = ?)" 
        UpdateCommand="UPDATE [Assets] SET [Host_Name] = ?, [Owner] = ?, [Manufacturer] = ?, [Model] = ?, [OS] = ?, [CPU] = ?, [Memory] = ?, [HD_Capacity] = ?, [Comments] = ?, [Picture] = ? WHERE [ID] = ?">
        <SelectParameters>
            <asp:ControlParameter ControlID="DropDownList1" DefaultValue="1" Name="ID" 
                PropertyName="SelectedValue" Type="Int32" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="ID" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="Host_Name" Type="String" />
            <asp:Parameter Name="Owner" Type="String" />
            <asp:Parameter Name="Manufacturer" Type="String" />
            <asp:Parameter Name="Model" Type="String" />
            <asp:Parameter Name="OS" Type="String" />
            <asp:Parameter Name="CPU" Type="String" />
            <asp:Parameter Name="Memory" Type="String" />
            <asp:Parameter Name="HD_Capacity" Type="String" />
            <asp:Parameter Name="Comments" Type="String" />
            <asp:Parameter Name="Picture" Type="String" />
            <asp:Parameter Name="ID" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="Host_Name" Type="String" />
            <asp:Parameter Name="Owner" Type="String" />
            <asp:Parameter Name="Manufacturer" Type="String" />
            <asp:Parameter Name="Model" Type="String" />
            <asp:Parameter Name="OS" Type="String" />
            <asp:Parameter Name="CPU" Type="String" />
            <asp:Parameter Name="Memory" Type="String" />
            <asp:Parameter Name="HD_Capacity" Type="String" />
            <asp:Parameter Name="Comments" Type="String" />
            <asp:Parameter Name="Picture" Type="String" />
        </InsertParameters>
    </asp:AccessDataSource>
    <asp:AccessDataSource ID="AccessDataSource2" runat="server" 
        DataFile="~/App_Data/Assets.mdb" 
        SelectCommand="SELECT [ID], [Owner] FROM [Assets]"></asp:AccessDataSource>
    <asp:DropDownList ID="DropDownList1" runat="server" 
        DataSourceID="AccessDataSource2" DataTextField="Owner" DataValueField="ID" 
        Height="25px" Width="224px" AutoPostBack="True">
    </asp:DropDownList>
    <asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" 
        AutoGenerateRows="False" CellPadding="4" DataKeyNames="ID" 
        DataSourceID="AccessDataSource1" ForeColor="#333333" GridLines="None" 
        Height="50px" Width="225px">
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <Fields>
            <asp:BoundField DataField="Host_Name" HeaderText="Host_Name" 
                SortExpression="Host_Name" />
            <asp:BoundField DataField="Owner" HeaderText="Owner" SortExpression="Owner" />
            <asp:BoundField DataField="Manufacturer" HeaderText="Manufacturer" 
                SortExpression="Manufacturer" />
            <asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" />
            <asp:BoundField DataField="OS" HeaderText="OS" SortExpression="OS" />
            <asp:BoundField DataField="CPU" HeaderText="CPU" SortExpression="CPU" />
            <asp:BoundField DataField="Memory" HeaderText="Memory" 
                SortExpression="Memory" />
            <asp:BoundField DataField="HD_Capacity" HeaderText="HD_Capacity" 
                SortExpression="HD_Capacity" />
            <asp:BoundField DataField="Comments" HeaderText="Comments" 
                SortExpression="Comments" />
            <asp:BoundField DataField="Picture" HeaderText="Picture" 
                SortExpression="Picture" />
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
                ShowInsertButton="True" />
        </Fields>
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#999999" />
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:DetailsView>
    </form>
    </body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of OMC2000
OMC2000
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Amazing work, thanks so much for your help OMC2000
OMC2000 thank you very much for your help, can you look at my other question? it's for the same website:

https://www.experts-exchange.com/questions/23820511/Displaying-a-picture-from-an-access-database-in-Visual-Web-Studio-2008.html