Problem in inserting data using DetailsView

L

le0

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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top