Solved

Why "Edit", "Delete", "New" on DetailsView does not work

Posted on 2012-03-17
3
420 Views
Last Modified: 2012-03-19
Hi:

We're creating some web application using VS 2010 with Visual Basic.

We try to insert a new record into an ACCESS table, or update/delete an existing record using DetailsView associated with AccessDataSource

We configure DetailsView to bind with the AccessDataSource and also configure the AccessDataSource for SELECT, INSERT, UPDATE, and DELETE statements.

In DetailsView we check "Enable Inserting", "Enable Editing", "Enable Deleting"

The problem is that when we try to update a record, after updating data in text boxes of DetailsView and clikcing "Update", the record is not updated.  When we try to deletea record, after clikcing "Delete", the record is not deleted. It is still there.

When we try to insert a new record, it crashes with the error "Primary key cannot be NULL" even though we carefully check to be sure that we enter the primary key - of text (not auto-number)

(NOTES: we can retrieve data from ACCESS table correctly - the DetailsView displays the data correctly)

If you know how to fix these problems, please help.

Thanks a lot,

Somits
0
Comment
Question by:somits
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
Comment Utility
Can you show your markup (aspx code)?

Do you call DataBind() again after updating, deleting etc?
0
 

Author Comment

by:somits
Comment Utility
Hi CodeCruiser:

I follow the instructions in the following links:


http://www.youtube.com/watch?v=vLa3_VB86oI

http://msdn.microsoft.com/en-us/library/ms178273.aspx

In which code I should call the databind(), would you give me an example?
With the links above, they don't mention anything about this.

Thanks a lot for your help,

Here is the aspx code of the body:

//-----------------------------------

<body>
    <form id="form1" runat="server">
        <uc1:VB_ASPNET_4Layout ID="VB_ASPNET_4Layout1" runat="server" />
        <div id="mncontent" style="Z-INDEX: 101; WIDTH: 100%; HEIGHT: 8px"></div>


        <asp:Panel ID="Panel1" runat="server"
            style="z-index: 1; left: 186px; top: 231px; position: absolute; height: 19px; width: 675px">
            <asp:AccessDataSource ID="AccessDataSource1" runat="server"
                DataFile="~/App_Data/Database3.accdb"
                DeleteCommand="DELETE FROM [vb_access_db3_tb2] WHERE [Order ID] = ?"
                InsertCommand="INSERT INTO [vb_access_db3_tb2] ([Order ID], [Amount], [Tax]) VALUES (?, ?, ?)"
                SelectCommand="SELECT * FROM [vb_access_db3_tb2]"
                UpdateCommand="UPDATE [vb_access_db3_tb2] SET [Amount] = ?, [Tax] = ? WHERE [Order ID] = ?">
                <DeleteParameters>
                    <asp:Parameter Name="Order_ID" Type="String" />
                </DeleteParameters>
                <InsertParameters>
                    <asp:Parameter Name="Order_ID" Type="String" />
                    <asp:Parameter Name="Amount" Type="Double" />
                    <asp:Parameter Name="Tax" Type="Double" />
                </InsertParameters>
                <UpdateParameters>
                    <asp:Parameter Name="Amount" Type="Double" />
                    <asp:Parameter Name="Tax" Type="Double" />
                    <asp:Parameter Name="Order_ID" Type="String" />
                </UpdateParameters>
            </asp:AccessDataSource>
        </asp:Panel>
        <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
            DataKeyNames="Order ID" DataSourceID="AccessDataSource1"
            style="z-index: 1; left: 189px; top: 342px; position: absolute; height: 105px; width: 265px">
            <Fields>
                <asp:BoundField DataField="Order ID" HeaderText="Order ID" ReadOnly="True"
                    SortExpression="Order ID" />
                <asp:BoundField DataField="Amount" HeaderText="Amount"
                    SortExpression="Amount" />
                <asp:BoundField DataField="Tax" HeaderText="Tax" SortExpression="Tax" />
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
                    ShowInsertButton="True" />
            </Fields>
        </asp:DetailsView>


    </form>
</body>
0
 

Author Comment

by:somits
Comment Utility
Hi CodeCruiser:

For more info, after clicking "Update" or "Delete" button in DetailsView and found that nothing has been changed, I checked the database. It's clear that the table is not changed at all. It seems that nothing occurs at the table.

Thanks for any help,

Somits
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now