Solved

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

Posted on 2012-03-17
3
421 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
ID: 37734960
Can you show your markup (aspx code)?

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

Author Comment

by:somits
ID: 37735275
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
ID: 37735486
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP.NET 5 Templates 2 65
C# Single Form 8 26
I need help making a collection from a class in VB.Net 3 23
Message not shown 5 29
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

919 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

12 Experts available now in Live!

Get 1:1 Help Now