locked
Having trouble inserting a record with detailview RRS feed

  • Question

  • User-763817100 posted

    Hi all, can anyone tell me what I'm doing wrong here please. Edit: I'm getting an error with my sql syntax.

     

    <LoggedInTemplate>

    <asp:DetailsView ID="dvInsertUser" runat="server" Height="50px" Width="125px"

    AutoGenerateInsertButton="True" AutoGenerateRows="False"

    DataKeyNames="RecordID" DataSourceID="ads3" DefaultMode="Insert"

    EnableModelValidation="True"

    >

    <Fields>

    <asp:BoundField DataField="RecordID" HeaderText="RecordID"

    InsertVisible="False" ReadOnly="True" SortExpression="RecordID" />

    <asp:BoundField DataField="LastName" HeaderText="LastName"

    SortExpression="LastName" />

    <asp:BoundField DataField="FirstName" HeaderText="FirstName"

    SortExpression="FirstName" />

    <asp:BoundField DataField="Address" HeaderText="Address"

    SortExpression="Address" />

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

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

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

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

    <asp:BoundField DataField="DateOfBirth" HeaderText="DateOfBirth"

    SortExpression="DateOfBirth" />

    <asp:BoundField DataField="MemberType" HeaderText="MemberType"

    SortExpression="MemberType" />

    <asp:BoundField DataField="AMANumber" HeaderText="AMANumber"

    SortExpression="AMANumber" />

    <asp:BoundField DataField="Email" HeaderText="Email"

    SortExpression="Email" />

    <asp:BoundField DataField="Channels" HeaderText="Channels"

    SortExpression="Channels" />

    <asp:CheckBoxField DataField="ClubOfficer" HeaderText="ClubOfficer"

    SortExpression="ClubOfficer" />

    <asp:CheckBoxField DataField="ShowDetails" HeaderText="ShowDetails"

    SortExpression="ShowDetails" />

    <asp:CheckBoxField InsertVisible="false" DataField="inactive" HeaderText="inactive"

    SortExpression="inactive" />

    </Fields>

    </asp:DetailsView>

    <asp:AccessDataSource ID="ads3" runat="server" DataFile="~/App_Data/ourmemberfile.mdb"

    SelectCommand="SELECT * FROM [Members]"

    InsertCommand="Insert Members (LastName, FirstName, Address, City, State, Zip, Phone, DateOfBirth, MemberType, AMANumber, Email, Channels, ClubOfficer, ShowDetails, inactive)

    Values (@LastName, @FirstName, @Address, @City, @State, @Zip, @Phone, @DateOfBirth, @MemberType, @AMANumber, @Email, @Channels, @ClubOfficer, @ShowDetails, False)"

    >

    </asp:AccessDataSource>

     

     

     

    Thank you for the help all. This is my first time trying to insert with this control.

     

    Monday, October 22, 2012 9:12 AM

Answers

  • User-1199946673 posted

    Hi all, can anyone tell me what I'm doing wrong here please

    You're missing the insertparameter collection

    <asp:AccessDataSource ID="ads3" runat="server" DataFile="~/App_Data/ourmemberfile.mdb"
    SelectCommand="SELECT * FROM [Members]"
    InsertCommand="Insert Members (LastName, FirstName, Address, City, State, Zip, Phone, DateOfBirth, MemberType, AMANumber, Email, Channels, ClubOfficer, ShowDetails, inactive) Values (@LastName, @FirstName, @Address, @City, @State, @Zip, @Phone, @DateOfBirth, @MemberType, @AMANumber, @Email, @Channels, @ClubOfficer, @ShowDetails, False)">
     <InsertParameters>
      <asp:parameter name="LastName" />
      <asp:parameter name="FirstName" />
      <asp:parameter name="Address" />
      <asp:parameter name="City" />
      <asp:parameter name="State" />
      <asp:parameter name="Zip" />
      <asp:parameter name="Phone" />
      <asp:parameter name="DateOfBirth" />
      <asp:parameter name="MemberType" />
      <asp:parameter name="AMANumber" />
      <asp:parameter name="Email" />
      <asp:parameter name="Channels" />
      <asp:parameter name="ClubOfficer" />
      <asp:parameter name="ShowDetails" />
     </InsertParameters>
    </asp:AccessDataSource>
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 22, 2012 5:12 PM
  • User-1716253493 posted

    Set default value for inactive=false in access file, then dont include it in insert command. And use ? to pass parameter

    InsertCommand="Insert Members 
    (LastName, FirstName, Address, City, State, Zip, Phone, DateOfBirth, MemberType, 
    AMANumber, Email, Channels, ClubOfficer, ShowDetails)
    
    Values
    (?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
    
    

    and add insertparamater from LastName to Showdetails

    <InsertParameters> 
      <asp:parameter name="LastName" /> 
      <asp:parameter name="FirstName" /> 
      <asp:parameter name="Address" /> 
      <asp:parameter name="City" /> 
      <asp:parameter name="State" /> 
      <asp:parameter name="Zip" /> 
      <asp:parameter name="Phone" /> 
      <asp:parameter name="DateOfBirth" /> 
      <asp:parameter name="MemberType" /> 
      <asp:parameter name="AMANumber" /> 
      <asp:parameter name="Email" /> 
      <asp:parameter name="Channels" /> 
      <asp:parameter name="ClubOfficer" /> 
      <asp:parameter name="ShowDetails" /> 
     </InsertParameters> 
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 22, 2012 9:07 PM

All replies

  • User-1199946673 posted

    Hi all, can anyone tell me what I'm doing wrong here please

    You're missing the insertparameter collection

    <asp:AccessDataSource ID="ads3" runat="server" DataFile="~/App_Data/ourmemberfile.mdb"
    SelectCommand="SELECT * FROM [Members]"
    InsertCommand="Insert Members (LastName, FirstName, Address, City, State, Zip, Phone, DateOfBirth, MemberType, AMANumber, Email, Channels, ClubOfficer, ShowDetails, inactive) Values (@LastName, @FirstName, @Address, @City, @State, @Zip, @Phone, @DateOfBirth, @MemberType, @AMANumber, @Email, @Channels, @ClubOfficer, @ShowDetails, False)">
     <InsertParameters>
      <asp:parameter name="LastName" />
      <asp:parameter name="FirstName" />
      <asp:parameter name="Address" />
      <asp:parameter name="City" />
      <asp:parameter name="State" />
      <asp:parameter name="Zip" />
      <asp:parameter name="Phone" />
      <asp:parameter name="DateOfBirth" />
      <asp:parameter name="MemberType" />
      <asp:parameter name="AMANumber" />
      <asp:parameter name="Email" />
      <asp:parameter name="Channels" />
      <asp:parameter name="ClubOfficer" />
      <asp:parameter name="ShowDetails" />
     </InsertParameters>
    </asp:AccessDataSource>
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 22, 2012 5:12 PM
  • User-1716253493 posted

    Set default value for inactive=false in access file, then dont include it in insert command. And use ? to pass parameter

    InsertCommand="Insert Members 
    (LastName, FirstName, Address, City, State, Zip, Phone, DateOfBirth, MemberType, 
    AMANumber, Email, Channels, ClubOfficer, ShowDetails)
    
    Values
    (?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
    
    

    and add insertparamater from LastName to Showdetails

    <InsertParameters> 
      <asp:parameter name="LastName" /> 
      <asp:parameter name="FirstName" /> 
      <asp:parameter name="Address" /> 
      <asp:parameter name="City" /> 
      <asp:parameter name="State" /> 
      <asp:parameter name="Zip" /> 
      <asp:parameter name="Phone" /> 
      <asp:parameter name="DateOfBirth" /> 
      <asp:parameter name="MemberType" /> 
      <asp:parameter name="AMANumber" /> 
      <asp:parameter name="Email" /> 
      <asp:parameter name="Channels" /> 
      <asp:parameter name="ClubOfficer" /> 
      <asp:parameter name="ShowDetails" /> 
     </InsertParameters> 
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 22, 2012 9:07 PM
  • User-763817100 posted

    Thanks guys, really appreciate the help.

    Monday, October 22, 2012 9:50 PM
  • User-1199946673 posted

    Set default value for inactive=false in access file, then dont include it in insert command

    That is just another option, but doesn't solve the problem

    And use ? to pass parameter

    Named parameters will work also

    and add insertparamater from LastName to Showdetails

    That is indeed causing the problem, as I already said!

    Tuesday, October 23, 2012 6:00 AM
  • User-1716253493 posted

    I just giving sugestion what i know, sorry pasting the parameters.

    I always use accessdatasource and sqldatasource in my app (not like code behind)

    I am very new here, appologize me.

    Tuesday, October 23, 2012 8:44 AM