Solved

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

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

813 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

15 Experts available now in Live!

Get 1:1 Help Now