Problem in inserting data using DetailsView

Discussion in 'ASP .Net' started by le0, Sep 25, 2006.

  1. le0

    le0 Guest

    Guys,

    I create a simple insertion in a database using DetailsView control, when i
    run this page and try to insert some data, the browser returns an error like
    this

    ---------------------------------------------------------------------------------------------------------------

    Server Error in '/Document' Application.

    You tried to assign the Null value to a variable that is not a Variant data
    type

    Description: An unhandled exception occured during the execution of the
    current web request.

    ----------------------------------------------------------------------------------------------------------------

    i filled up all fields that is required and follow all its data type to make
    sure no errors will return, but that doesnt solve my problem, can you figure
    this out? btw i use MS Access as my database.

    heres my code for your reference...

    <form id="form1" runat="server">

    <div>

    &nbsp;&nbsp;</div>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
    ConnectionStrings:MyBooksConnectionString %>"

    DeleteCommand="DELETE FROM [Book1] WHERE [BookID] = ? AND [Author] = ? AND
    [YearPublished] = ? AND [ISBN] = ?" InsertCommand="INSERT INTO [Book1]
    ([BookID], [Author], [YearPublished], [ISBN]) VALUES (?, ?, ?, ?)"

    ProviderName="<%$ ConnectionStrings:MyBooksConnectionString.ProviderName %>"

    SelectCommand="SELECT [BookID], [Author], [YearPublished], [ISBN] FROM
    [Book1]" UpdateCommand="UPDATE [Book1] SET [Author] = ?, [YearPublished] =
    ?, [ISBN] = ? WHERE [BookID] = ? AND [Author] = ? AND [YearPublished] = ?
    AND [ISBN] = ?" ConflictDetection="CompareAllValues"
    OldValuesParameterFormatString="original_{0}">

    <DeleteParameters>

    <asp:parameter Name="original_BookID" Type="Int32" />

    <asp:parameter Name="original_Author" Type="String" />

    <asp:parameter Name="original_YearPublished" Type="Int32" />

    <asp:parameter Name="original_ISBN" Type="String" />

    </DeleteParameters>

    <UpdateParameters>

    <asp:parameter Name="Author" Type="String" />

    <asp:parameter Name="YearPublished" Type="Int32" />

    <asp:parameter Name="ISBN" Type="String" />

    <asp:parameter Name="original_BookID" Type="Int32" />

    <asp:parameter Name="original_Author" Type="String" />

    <asp:parameter Name="original_YearPublished" Type="Int32" />

    <asp:parameter Name="original_ISBN" Type="String" />

    </UpdateParameters>

    <InsertParameters>

    <asp:parameter Name="BookID" Type="Int32" />

    <asp:parameter Name="Author" Type="String" />

    <asp:parameter Name="YearPublished" Type="Int32" />

    <asp:parameter Name="ISBN" Type="String" />

    </InsertParameters>

    </asp:SqlDataSource>

    &nbsp;

    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
    DataKeyNames="BookID"

    DataSourceID="SqlDataSource1" Height="50px" Style="z-index: 100; left: 14px;

    position: absolute; top: 77px" Width="125px">

    <Fields>

    <asp:BoundField DataField="BookID" HeaderText="BookID" InsertVisible="False"
    ReadOnly="True"

    SortExpression="BookID" />

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

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

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

    <asp:CommandField ShowInsertButton="True" />

    </Fields>

    </asp:DetailsView>

    </form>
     
    le0, Sep 25, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nick
    Replies:
    0
    Views:
    525
  2. tom c
    Replies:
    0
    Views:
    457
    tom c
    Sep 19, 2006
  3. Replies:
    0
    Views:
    370
  4. David Ching
    Replies:
    0
    Views:
    386
    David Ching
    Aug 29, 2007
  5. Feege
    Replies:
    0
    Views:
    471
    Feege
    Dec 20, 2005
Loading...

Share This Page