Solved

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

Posted on 2012-03-17
3
424 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
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…
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…

726 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