Solved

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

Posted on 2012-03-17
3
425 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

690 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