asp:AccessDataSource asp:DetailsView, Inserting a record with an autonumer as primary key.

Rate It (2)

Last post 07-04-2009 5:33 PM by hans_v. 9 replies.

Sort Posts:

  • asp:AccessDataSource asp:DetailsView, Inserting a record with an autonumer as primary key.

    08-21-2005, 8:54 AM
    • Member
      15 point Member
    • Engineer_Matt
    • Member since 08-21-2005, 10:10 AM
    • Posts 3
    Took me a day to figure this out, so Id thaught I'd post it.  Using Visual Web Developer 2005 EE and ASP.NET 2.0
    If you insert an AccessDataSource linking to a table with a primary key that is an autonumber, the script that is inserted is shown below.  If you want to insert a record (Using a DetailsView object) you get the following error: "
    "You tried to assign the Null value to a variable that is not a Variant data type." .  To correct the problem, remove the highlighted (BOLD) code below:

    <asp:AccessDataSource ID="AccessDataSource1" runat="server" ConflictDetection="CompareAllValues"
                DataFile="~/App_Data/CDR.mdb" DeleteCommand="DELETE FROM [T_PersonData] WHERE [PersonID] = ? AND [PersonLastName] = ? AND [PersonFirstName] = ? AND [PersonInitial] = ? AND [PersonCompany] = ? AND [PersonComment] = ? AND [PersonContactPh] = ?"
                InsertCommand="INSERT INTO [T_PersonData] ([PersonID], [PersonLastName], [PersonFirstName], [PersonInitial], [PersonCompany], [PersonComment], [PersonContactPh]) VALUES (?, ?, ?, ?, ?, ?, ?)"
                SelectCommand="SELECT * FROM [T_PersonData]" UpdateCommand="UPDATE [T_PersonData] SET [PersonLastName] = ?, [PersonFirstName] = ?, [PersonInitial] = ?, [PersonCompany] = ?, [PersonComment] = ?, [PersonContactPh] = ? WHERE [PersonID] = ? AND [PersonLastName] = ? AND [PersonFirstName] = ? AND [PersonInitial] = ? AND [PersonCompany] = ? AND [PersonComment] = ? AND [PersonContactPh] = ?">
                <DeleteParameters>
                    <asp:Parameter Name="original_PersonID" Type="Int32" />
                    <asp:Parameter Name="original_PersonLastName" Type="String" />
                    <asp:Parameter Name="original_PersonFirstName" Type="String" />
                    <asp:Parameter Name="original_PersonInitial" Type="String" />
                    <asp:Parameter Name="original_PersonCompany" Type="String" />
                    <asp:Parameter Name="original_PersonComment" Type="String" />
                    <asp:Parameter Name="original_PersonContactPh" Type="String" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="PersonLastName" Type="String" />
                    <asp:Parameter Name="PersonFirstName" Type="String" />
                    <asp:Parameter Name="PersonInitial" Type="String" />
                    <asp:Parameter Name="PersonCompany" Type="String" />
                    <asp:Parameter Name="PersonComment" Type="String" />
                    <asp:Parameter Name="PersonContactPh" Type="String" />
                    <asp:Parameter Name="original_PersonID" Type="Int32" />
                    <asp:Parameter Name="original_PersonLastName" Type="String" />
                    <asp:Parameter Name="original_PersonFirstName" Type="String" />
                    <asp:Parameter Name="original_PersonInitial" Type="String" />
                    <asp:Parameter Name="original_PersonCompany" Type="String" />
                    <asp:Parameter Name="original_PersonComment" Type="String" />
                    <asp:Parameter Name="original_PersonContactPh" Type="String" />
                </UpdateParameters>
                <InsertParameters>
                    <asp:Parameter Name="PersonID" Type="Int32" />
                    <asp:Parameter Name="PersonLastName" Type="String" />
                    <asp:Parameter Name="PersonFirstName" Type="String" />
                    <asp:Parameter Name="PersonInitial" Type="String" />
                    <asp:Parameter Name="PersonCompany" Type="String" />
                    <asp:Parameter Name="PersonComment" Type="String" />
                    <asp:Parameter Name="PersonContactPh" Type="String" />
                </InsertParameters>
            </asp:AccessDataSource>


    Removing the code prevents the asp scipt from attempting to enter a null value into the primary key.

    Matt
  • Re: asp:AccessDataSource asp:DetailsView, Inserting a record with an autonumer as primary key.

    04-22-2006, 6:30 PM
    • Member
      451 point Member
    • jdanforth
    • Member since 11-12-2003, 2:46 PM
    • Sweden
    • Posts 16

    Perfect, thanks. I had this problem for sure, and your post helped.

    (thumbs up)

    /Johan
  • Re: asp:AccessDataSource asp:DetailsView, Inserting a record with an autonumer as primary key.

    09-14-2006, 8:01 PM
    • Member
      31 point Member
    • MikeyBoyd
    • Member since 09-14-2006, 11:59 PM
    • Posts 11
    Thanks you very much, worked perfectly...this was driving me nuts....seems such a basic flaw in VWD?
  • Re: asp:AccessDataSource asp:DetailsView, Inserting a record with an autonumer as primary key.

    10-05-2006, 7:33 PM
    • Member
      161 point Member
    • ban
    • Member since 10-05-2006, 11:28 PM
    • Posts 42

    Big Smile it was  a great solution.

     

    Thank you very much.

  • Re: asp:AccessDataSource asp:DetailsView, Inserting a record with an autonumer as primary key.

    11-28-2006, 1:44 PM
    • Member
      5 point Member
    • pajamas98
    • Member since 02-17-2004, 9:30 PM
    • Posts 1
    ban:

    Big Smile it was  a great solution.

    Thank you very much.

     Yes, I've finally got this VWD bug fix  to work too.   Now, if Microsoft will just listen and do an official fix.

     Thanks.

     

  • Re: asp:AccessDataSource asp:DetailsView, Inserting a record with an autonumer as primary key.

    05-19-2007, 6:53 PM
    • Member
      2 point Member
    • zoomer56
    • Member since 05-19-2007, 10:51 PM
    • Posts 1

    This solution will save me from more wasted time!  thanks for posting 

  • Re: asp:AccessDataSource asp:DetailsView, Inserting a record with an autonumer as primary key.

    01-03-2008, 1:27 PM
    • Member
      4 point Member
    • jamvan55
    • Member since 01-03-2008, 6:26 PM
    • Posts 43

    Hi guys, I saw that this worked for many of you, but when I try to remove the BOLD I get a different error. Anywhere, perhaps you can have a look at my code and BOLD where I need to delete. Many thanks in advance.

    <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Test.aspx.vb" Inherits="Test" title="Untitled Page" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <asp:FormView ID="FormView1" runat="server" DataKeyNames="ID" DataSourceID="AddDataSource"
            Font-Names="Tahoma" Font-Size="10pt" ForeColor="White">
            <EditItemTemplate>
                ID:
                <asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>'></asp:Label><br />
                Auth No:
                <asp:TextBox ID="Auth_NoTextBox" runat="server" Text='<%# Bind("[Auth No]") %>'>
                </asp:TextBox><br />
                Caller:
                <asp:TextBox ID="CallerTextBox" runat="server" Text='<%# Bind("Caller") %>'>
                </asp:TextBox><br />
                Date:
                <asp:TextBox ID="DateTextBox" runat="server" Text='<%# Bind("Date") %>'>
                </asp:TextBox><br />
                Time:
                <asp:TextBox ID="TimeTextBox" runat="server" Text='<%# Bind("Time") %>'>
                </asp:TextBox><br />
                H S No:
                <asp:TextBox ID="H_S_NoTextBox" runat="server" Text='<%# Bind("[H S No]") %>'>
                </asp:TextBox><br />
                Contractor:
                <asp:TextBox ID="ContractorTextBox" runat="server" Text='<%# Bind("Contractor") %>'>
                </asp:TextBox><br />
                Origin:
                <asp:TextBox ID="OriginTextBox" runat="server" Text='<%# Bind("Origin") %>'>
                </asp:TextBox><br />
                Destination:
                <asp:TextBox ID="DestinationTextBox" runat="server" Text='<%# Bind("Destination") %>'>
                </asp:TextBox><br />
                Modification Requested:
                <asp:TextBox ID="Modification_RequestedTextBox" runat="server" Text='<%# Bind("[Modification Requested]") %>'>
                </asp:TextBox><br />
                Trailer Number:
                <asp:TextBox ID="Trailer_NumberTextBox" runat="server" Text='<%# Bind("[Trailer Number]") %>'>
                </asp:TextBox><br />
                Pull Date:
                <asp:TextBox ID="Pull_DateTextBox" runat="server" Text='<%# Bind("[Pull Date]") %>'>
                </asp:TextBox><br />
                Pull Time:
                <asp:TextBox ID="Pull_TimeTextBox" runat="server" Text='<%# Bind("[Pull Time]") %>'>
                </asp:TextBox><br />
                Contractor Date:
                <asp:TextBox ID="Contractor_DateTextBox" runat="server" Text='<%# Bind("[Contractor Date]") %>'>
                </asp:TextBox><br />
                Contractor Time:
                <asp:TextBox ID="Contractor_TimeTextBox" runat="server" Text='<%# Bind("[Contractor Time]") %>'>
                </asp:TextBox><br />
                CDO:
                <asp:TextBox ID="CDOTextBox" runat="server" Text='<%# Bind("CDO") %>'>
                </asp:TextBox><br />
                Message Number and comments:
                <asp:TextBox ID="Message_Number_and_commentsTextBox" runat="server" Text='<%# Bind("[Message Number and comments]") %>'>
                </asp:TextBox><br />
                Type:
                <asp:TextBox ID="TypeTextBox" runat="server" Text='<%# Bind("Type") %>'>
                </asp:TextBox><br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                    Text="Update">
                </asp:LinkButton>
                <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                    Text="Cancel">
                </asp:LinkButton>
            </EditItemTemplate>
            <InsertItemTemplate>
                Auth No:
                <asp:TextBox ID="Auth_NoTextBox" runat="server" Text='<%# Bind("[Auth No]") %>'></asp:TextBox><br />
                Caller:
                <asp:TextBox ID="CallerTextBox" runat="server" Text='<%# Bind("Caller") %>'></asp:TextBox><br />
                Date:
                <asp:TextBox ID="DateTextBox" runat="server" Text='<%# Bind("Date") %>'></asp:TextBox><br />
                Time:
                <asp:TextBox ID="TimeTextBox" runat="server" Text='<%# Bind("Time") %>'></asp:TextBox><br />
                H S No:
                <asp:TextBox ID="H_S_NoTextBox" runat="server" Text='<%# Bind("[H S No]") %>'></asp:TextBox><br />
                Contractor:
                <asp:TextBox ID="ContractorTextBox" runat="server" Text='<%# Bind("Contractor") %>'></asp:TextBox><br />
                Origin:
                <asp:TextBox ID="OriginTextBox" runat="server" Text='<%# Bind("Origin") %>'></asp:TextBox><br />
                Destination:
                <asp:TextBox ID="DestinationTextBox" runat="server" Text='<%# Bind("Destination") %>'></asp:TextBox><br />
                Modification Requested:
                <asp:TextBox ID="Modification_RequestedTextBox" runat="server" Text='<%# Bind("[Modification Requested]") %>'></asp:TextBox><br />
                Trailer Number:
                <asp:TextBox ID="Trailer_NumberTextBox" runat="server" Text='<%# Bind("[Trailer Number]") %>'></asp:TextBox><br />
                Pull Date:
                <asp:TextBox ID="Pull_DateTextBox" runat="server" Text='<%# Bind("[Pull Date]") %>'></asp:TextBox><br />
                Pull Time:
                <asp:TextBox ID="Pull_TimeTextBox" runat="server" Text='<%# Bind("[Pull Time]") %>'></asp:TextBox><br />
                Contractor Date:
                <asp:TextBox ID="Contractor_DateTextBox" runat="server" Text='<%# Bind("[Contractor Date]") %>'></asp:TextBox><br />
                Contractor Time:
                <asp:TextBox ID="Contractor_TimeTextBox" runat="server" Text='<%# Bind("[Contractor Time]") %>'></asp:TextBox><br />
                CDO:
                <asp:TextBox ID="CDOTextBox" runat="server" Text='<%# Bind("CDO") %>'></asp:TextBox><br />
                Message Number and comments:
                <asp:TextBox ID="Message_Number_and_commentsTextBox" runat="server" Text='<%# Bind("[Message Number and comments]") %>'></asp:TextBox><br />
                Type:
                <asp:TextBox ID="TypeTextBox" runat="server" Text='<%# Bind("Type") %>'></asp:TextBox><br />
                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                    Text="Insert"></asp:LinkButton>
                <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                    Text="Cancel"></asp:LinkButton>
            </InsertItemTemplate>
            <ItemTemplate>
                ID:
                <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>'></asp:Label><br />
                Auth No:
                <asp:Label ID="Auth_NoLabel" runat="server" Text='<%# Bind("[Auth No]") %>'></asp:Label><br />
                Caller:
                <asp:Label ID="CallerLabel" runat="server" Text='<%# Bind("Caller") %>'></asp:Label><br />
                Date:
                <asp:Label ID="DateLabel" runat="server" Text='<%# Bind("Date") %>'></asp:Label><br />
                Time:
                <asp:Label ID="TimeLabel" runat="server" Text='<%# Bind("Time") %>'></asp:Label><br />
                H S No:
                <asp:Label ID="H_S_NoLabel" runat="server" Text='<%# Bind("[H S No]") %>'></asp:Label><br />
                Contractor:
                <asp:Label ID="ContractorLabel" runat="server" Text='<%# Bind("Contractor") %>'></asp:Label><br />
                Origin:
                <asp:Label ID="OriginLabel" runat="server" Text='<%# Bind("Origin") %>'></asp:Label><br />
                Destination:
                <asp:Label ID="DestinationLabel" runat="server" Text='<%# Bind("Destination") %>'></asp:Label><br />
                Modification Requested:
                <asp:Label ID="Modification_RequestedLabel" runat="server" Text='<%# Bind("[Modification Requested]") %>'></asp:Label><br />
                Trailer Number:
                <asp:Label ID="Trailer_NumberLabel" runat="server" Text='<%# Bind("[Trailer Number]") %>'></asp:Label><br />
                Pull Date:
                <asp:Label ID="Pull_DateLabel" runat="server" Text='<%# Bind("[Pull Date]") %>'></asp:Label><br />
                Pull Time:
                <asp:Label ID="Pull_TimeLabel" runat="server" Text='<%# Bind("[Pull Time]") %>'></asp:Label><br />
                Contractor Date:
                <asp:Label ID="Contractor_DateLabel" runat="server" Text='<%# Bind("[Contractor Date]") %>'></asp:Label><br />
                Contractor Time:
                <asp:Label ID="Contractor_TimeLabel" runat="server" Text='<%# Bind("[Contractor Time]") %>'></asp:Label><br />
                CDO:
                <asp:Label ID="CDOLabel" runat="server" Text='<%# Bind("CDO") %>'></asp:Label><br />
                Message Number and comments:
                <asp:Label ID="Message_Number_and_commentsLabel" runat="server" Text='<%# Bind("[Message Number and comments]") %>'></asp:Label><br />
                Type:
                <asp:Label ID="TypeLabel" runat="server" Text='<%# Bind("Type") %>'></asp:Label><br />
                <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
                    Text="Edit"></asp:LinkButton>
                <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
                    Text="Delete"></asp:LinkButton>
                <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
                    Text="New"></asp:LinkButton>
            </ItemTemplate>
        </asp:FormView>
        &nbsp; &nbsp;
        <asp:AccessDataSource ID="AddDataSource" runat="server"
            DataFile="~/App_Data/NCCAuth.mdb" DeleteCommand="DELETE FROM [TblMain] WHERE [ID] = ?"
            InsertCommand="INSERT INTO [TblMain] ([ID], [Auth No], [Caller], [Date], [Time], [H S No], [Contractor], [Origin], [Destination], [Modification Requested], [Trailer Number], [Pull Date], [Pull Time], [Contractor Date], [Contractor Time], [CDO], [Message Number and comments], [Type]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
            OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [TblMain]"
            UpdateCommand="UPDATE [TblMain] SET [Auth No] = ?, [Caller] = ?, [Date] = ?, [Time] = ?, [H S No] = ?, [Contractor] = ?, [Origin] = ?, [Destination] = ?, [Modification Requested] = ?, [Trailer Number] = ?, [Pull Date] = ?, [Pull Time] = ?, [Contractor Date] = ?, [Contractor Time] = ?, [CDO] = ?, [Message Number and comments] = ?, [Type] = ? WHERE [ID] = ?">
            <DeleteParameters>
                <asp:Parameter Name="original_ID" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="Auth_No" Type="String" />
                <asp:Parameter Name="Caller" Type="String" />
                <asp:Parameter Name="Date" Type="String" />
                <asp:Parameter Name="Time" Type="String" />
                <asp:Parameter Name="H_S_No" Type="String" />
                <asp:Parameter Name="Contractor" Type="String" />
                <asp:Parameter Name="Origin" Type="String" />
                <asp:Parameter Name="Destination" Type="String" />
                <asp:Parameter Name="Modification_Requested" Type="String" />
                <asp:Parameter Name="Trailer_Number" Type="String" />
                <asp:Parameter Name="Pull_Date" Type="String" />
                <asp:Parameter Name="Pull_Time" Type="String" />
                <asp:Parameter Name="Contractor_Date" Type="String" />
                <asp:Parameter Name="Contractor_Time" Type="String" />
                <asp:Parameter Name="CDO" Type="String" />
                <asp:Parameter Name="Message_Number_and_comments" Type="String" />
                <asp:Parameter Name="Type" Type="String" />
                <asp:Parameter Name="original_ID" Type="Int32" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="ID" Type="Int32" />
                <asp:Parameter Name="Auth_No" Type="String" />
                <asp:Parameter Name="Caller" Type="String" />
                <asp:Parameter Name="Date" Type="String" />
                <asp:Parameter Name="Time" Type="String" />
                <asp:Parameter Name="H_S_No" Type="String" />
                <asp:Parameter Name="Contractor" Type="String" />
                <asp:Parameter Name="Origin" Type="String" />
                <asp:Parameter Name="Destination" Type="String" />
                <asp:Parameter Name="Modification_Requested" Type="String" />
                <asp:Parameter Name="Trailer_Number" Type="String" />
                <asp:Parameter Name="Pull_Date" Type="String" />
                <asp:Parameter Name="Pull_Time" Type="String" />
                <asp:Parameter Name="Contractor_Date" Type="String" />
                <asp:Parameter Name="Contractor_Time" Type="String" />
                <asp:Parameter Name="CDO" Type="String" />
                <asp:Parameter Name="Message_Number_and_comments" Type="String" />
                <asp:Parameter Name="Type" Type="String" />
            </InsertParameters>
        </asp:AccessDataSource>
        <asp:AccessDataSource ID="ContractorDataSource" runat="server" DataFile="~/App_Data/NCCAuth.mdb"
            SelectCommand="SELECT [Carriers] FROM [Carriers Query]"></asp:AccessDataSource>
    </asp:Content> 

     

  • Re: asp:AccessDataSource asp:DetailsView, Inserting a record with an autonumer as primary key.

    11-18-2008, 3:24 PM
    • Member
      4 point Member
    • slimx3m
    • Member since 11-18-2008, 3:40 AM
    • Posts 7

    that was it?!Big Smile

     

    thank you so much, i've having the same problem and been working on it for 2 hrs. i guess i should of search after 30mins. Stick out tongue

  • Re: asp:AccessDataSource asp:DetailsView, Inserting a record with an autonumer as primary key.

    07-04-2009, 12:55 PM
    • Member
      2 point Member
    • summeroffBob
    • Member since 07-04-2009, 4:45 PM
    • Posts 1

     I encountered the same problem with Visual Studio 2008. I deleted my TID (stands for teacher ID) field per the suggestions. I tried detailview control. It seemed to work fine -- accepted the imput -- but the only data that was posted to the Access DB was email and the generated TID. All other fields are blank. Any help you can offer would be appreciated.

     <asp:AccessDataSource ID="AccessDataSource1" runat="server" ConflictDetection="CompareAllValues" DataFile="~/App_Data/FINAOsms_empty.mdb"

    DeleteCommand="DELETE FROM [Teacher Setup Information] WHERE [TID] = ? AND (([Teacher First Name] = ?) OR ([Teacher First Name] IS NULL AND ? IS NULL)) AND (([Teacher Last Name] = ?) OR ([Teacher Last Name] IS NULL AND ? IS NULL)) AND (([Teacher Displayed Name] = ?) OR ([Teacher Displayed Name] IS NULL AND ? IS NULL)) AND (([Room Number] = ?) OR ([Room Number] IS NULL AND ? IS NULL)) AND (([Room Location] = ?) OR ([Room Location] IS NULL AND ? IS NULL)) AND ((Email = ?) OR (Email IS NULL AND ? IS NULL)) AND (([Web Site Address] = ?) OR ([Web Site Address] IS NULL AND ? IS NULL)) AND (([Phone Number] = ?) OR ([Phone Number] IS NULL AND ? IS NULL)) AND (([Extension] = ?) OR ([Extension] IS NULL AND ? IS NULL))"

    InsertCommand="INSERT INTO [Teacher Setup Information] ([Teacher First Name], [Teacher Last Name], [Teacher Displayed Name], [Room Number], [Room Location], Email, [Web Site Address], [Phone Number], [Extension]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"

    OldValuesParameterFormatString="original_{0}"

    SelectCommand="SELECT * FROM [Teacher Setup Information]"

    UpdateCommand="UPDATE [Teacher Setup Information] SET [Teacher First Name] = ?, [Teacher Last Name] = ?, [Teacher Displayed Name] = ?, [Room Number] = ?, [Room Location] = ?, Email = ?, [Web Site Address] = ?, [Phone Number] = ?, [Extension] = ? WHERE [TID] = ? AND (([Teacher First Name] = ?) OR ([Teacher First Name] IS NULL AND ? IS NULL)) AND (([Teacher Last Name] = ?) OR ([Teacher Last Name] IS NULL AND ? IS NULL)) AND (([Teacher Displayed Name] = ?) OR ([Teacher Displayed Name] IS NULL AND ? IS NULL)) AND (([Room Number] = ?) OR ([Room Number] IS NULL AND ? IS NULL)) AND (([Room Location] = ?) OR ([Room Location] IS NULL AND ? IS NULL)) AND ((Email = ?) OR (Email IS NULL AND ? IS NULL)) AND (([Web Site Address] = ?) OR ([Web Site Address] IS NULL AND ? IS NULL)) AND (([Phone Number] = ?) OR ([Phone Number] IS NULL AND ? IS NULL)) AND (([Extension] = ?) OR ([Extension] IS NULL AND ? IS NULL))">

     

    <DeleteParameters>

     <asp:Parameter Name="original_TID" Type="Int32" />

     

    <asp:Parameter Name="original_Teacher_First_Name" Type="String" />

     

    <asp:Parameter Name="original_Teacher_Last_Name" Type="String" />

     

    <asp:Parameter Name="original_Teacher_Displayed_Name" Type="String" />

     

    <asp:Parameter Name="original_Room_Number" Type="String" />

     

    <asp:Parameter Name="original_Room_Location" Type="String" />

     

    <asp:Parameter Name="original_email" Type="String" />

     

    <asp:Parameter Name="original_Web_Site_Address" Type="String" />

     

    <asp:Parameter Name="original_Phone_Number" Type="String" />

     

    <asp:Parameter Name="original_Extension" Type="String" />

     

    </DeleteParameters>

     

    <UpdateParameters>

     

    <asp:Parameter Name="Teacher_First_Name" Type="String" />

     

    <asp:Parameter Name="Teacher_Last_Name" Type="String" />

     

    <asp:Parameter Name="Teacher_Displayed_Name" Type="String" />

     

    <asp:Parameter Name="Room_Number" Type="String" />

     

    <asp:Parameter Name="Room_Location" Type="String" />

     

    <asp:Parameter Name="email" Type="String" />

     

    <asp:Parameter Name="Web_Site_Address" Type="String" />

     

    <asp:Parameter Name="Phone_Number" Type="String" />

     

    <asp:Parameter Name="Extension" Type="String" />

     

    <asp:Parameter Name="original_TID" Type="Int32" />

     

    <asp:Parameter Name="original_Teacher_First_Name" Type="String" />

     

    <asp:Parameter Name="original_Teacher_Last_Name" Type="String" />

     

    <asp:Parameter Name="original_Teacher_Displayed_Name" Type="String" />

     

    <asp:Parameter Name="original_Room_Number" Type="String" />

     

    <asp:Parameter Name="original_Room_Location" Type="String" />

     

    <asp:Parameter Name="original_email" Type="String" />

     

    <asp:Parameter Name="original_Web_Site_Address" Type="String" />

     

    <asp:Parameter Name="original_Phone_Number" Type="String" />

     

    <asp:Parameter Name="original_Extension" Type="String" />

     

    </UpdateParameters>

     

    <InsertParameters>

     

    <asp:Parameter Name="Teacher_First_Name" Type="String" />

     

    <asp:Parameter Name="Teacher_Last_Name" Type="String" />

     

    <asp:Parameter Name="Teacher_Displayed_Name" Type="String" />

     

    <asp:Parameter Name="Room_Number" Type="String" />

     

    <asp:Parameter Name="Room_Location" Type="String" />

     

    <asp:Parameter Name="email" Type="String" />

     

    <asp:Parameter Name="Web_Site_Address" Type="String" />

     

    <asp:Parameter Name="Phone_Number" Type="String" />

     

    <asp:Parameter Name="Extension" Type="String" />

     

     

    </InsertParameters>

     

    </asp:AccessDataSource>

     

    <br />

     

     

     

    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="TID" DataSourceID="AccessDataSource1" Height="50px" Width="332px" AllowPaging="True">

     

    <Fields>

     

     

    <asp:BoundField DataField="Teacher First Name" HeaderText="Teacher First Name" SortExpression="Teacher First Name" />

     

     

    <asp:BoundField DataField="Teacher Last Name" HeaderText="Teacher Last Name" SortExpression="Teacher Last Name" />

     

     

    <asp:BoundField DataField="Teacher Displayed Name" HeaderText="Teacher Displayed Name" SortExpression="Teacher Displayed Name" />

     

     

    <asp:BoundField DataField="Room Number" HeaderText="Room Number" SortExpression="Room Number" />

     

     

    <asp:BoundField DataField="Room Location" HeaderText="Room Location" SortExpression="Room Location" />

     

    <asp:BoundField DataField="email" HeaderText="email" SortExpression="email" />

     

     

    <asp:BoundField DataField="Web Site Address" HeaderText="Web Site Address" SortExpression="Web Site Address" />

     

     

    <asp:BoundField DataField="Phone Number" HeaderText="Phone Number" SortExpression="Phone Number" />

     

     

    <asp:BoundField DataField="Extension" HeaderText="Extension" SortExpression="Extension" />

     

     

    <asp:BoundField DataField="TID" HeaderText="TID" InsertVisible="False" ReadOnly="True" SortExpression="TID" />

     

     

    <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True" />

     

    </Fields>

     

    </asp:DetailsView>

     

  • Re: asp:AccessDataSource asp:DetailsView, Inserting a record with an autonumer as primary key.

    07-04-2009, 5:33 PM
    • Star
      9,496 point Star
    • hans_v
    • Member since 01-29-2007, 4:03 PM
    • Posts 1,645

     When you have a question, please don't reopen a very old topic, even if you think your question is related.

    http://www.mikesdotnetting.com/Article.aspx?ArticleID=69

    When looking to your code, I think inserting a record will not be a problem, since the insertcommand seems fine to me.

    But the Delete and the Update Commands will not work, because of the number of parameters in the SQL command do not match the number op parameters in the parameter collection. You're using a questionmark as parametername, which is fine, as long if you're using a parameter only once, because every questionmark is treated as a seperate parameter. But you want to use some parameters twice, for example in

    (([Teacher First Name] = ?) OR ([Teacher First Name] IS NULL AND ? IS NULL))

    But how would ASP.NET understand that both questionmarks both are pointing to the Teacher_First_Name parameter? When you want to use a parameter mulitple times in a command, you shouldn't use questionmarks, but you should name them, like in SQL Server:

    (([Teacher First Name] = @TeacherFirstName) OR ([Teacher First Name] IS NULL AND @TeacherFirstName IS NULL))

    That will solve the problem, but anther question is can [Teacher First Name] be a null value? If it's a mandatory field than the answer is definitly NO. But if it isn't a mandatory field, I prefer to fille it with an empty string, rather than a Null value. In that case, there is no need for checking on Null values, so you can skip everything after the OR:

    ([Teacher First Name] = @TeacherFirstName)

    Next question is, did you set ConflictDetection="CompareAllValues" on purpose, and do you know what it means. It makes your query's much longer and you need to explain to users why a record isn't updated or deleted?

Page 1 of 1 (10 items)