Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error: You tried to assign the Null value to a variable that is not a

Status
Not open for further replies.

redcare

Technical User
May 20, 2001
32
0
0
GB
Hi

I keep getting the following error:

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

When trying to insert a new record into an Access 2003 Database using the Details View tool. I have tried using a seperate entry page as well as adding the insert option in Details View but each time I still get the above error.

Any help will be gratefully recieved.

Here is the code I'm using:

<body>
<form id="form1" runat="server">
<div>
<br />
&nbsp; &nbsp;&nbsp;<br />
&nbsp; &nbsp;
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" /><br />
&nbsp;<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:EMCServerlistLatest %>"
DeleteCommand="DELETE FROM [SIRIUS_Contacts] WHERE [ID] = ?" InsertCommand="INSERT INTO [SIRIUS_Contacts] ([SiteName], [Trinome], [Address], [floor], [PostCode], [Primary_Onsite_Contact], [Primary_Onsite_Contact_Number], [Secondary_Onsite_Contact], [ID], [Secondary_Onsite_Contact_Number]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
ProviderName="<%$ ConnectionStrings:EMCServerlistLatest.ProviderName %>" SelectCommand="SELECT * FROM [SIRIUS_Contacts] WHERE ([Trinome] LIKE '%' + ? + '%')"
UpdateCommand="UPDATE [SIRIUS_Contacts] SET [SiteName] = ?, [Trinome] = ?, [Address] = ?, [floor] = ?, [PostCode] = ?, [Primary_Onsite_Contact] = ?, [Primary_Onsite_Contact_Number] = ?, [Secondary_Onsite_Contact] = ?, [Secondary_Onsite_Contact_Number] = ? WHERE [ID] = ?">
<DeleteParameters>
<asp:parameter Name="ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="SiteName" Type="String" />
<asp:parameter Name="Trinome" Type="String" />
<asp:parameter Name="Address" Type="String" />
<asp:parameter Name="floor" Type="String" />
<asp:parameter Name="PostCode" Type="String" />
<asp:parameter Name="Primary_Onsite_Contact" Type="String" />
<asp:parameter Name="Primary_Onsite_Contact_Number" Type="String" />
<asp:parameter Name="Secondary_Onsite_Contact" Type="String" />
<asp:parameter Name="Secondary_Onsite_Contact_Number" Type="String" />
<asp:parameter Name="ID" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" Name="Trinome" PropertyName="Text" Type="String" />
</SelectParameters>
<InsertParameters>
<asp:parameter Name="SiteName" Type="String" />
<asp:parameter Name="Trinome" Type="String" />
<asp:parameter Name="Address" Type="String" />
<asp:parameter Name="floor" Type="String" />
<asp:parameter Name="PostCode" Type="String" />
<asp:parameter Name="Primary_Onsite_Contact" Type="String" />
<asp:parameter Name="Primary_Onsite_Contact_Number" Type="String" />
<asp:parameter Name="Secondary_Onsite_Contact" Type="String" />
<asp:parameter Name="ID" Type="Int32" />
<asp:parameter Name="Secondary_Onsite_Contact_Number" Type="String" />
</InsertParameters>
</asp:SqlDataSource>

</div>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="ID"
DataSourceID="SqlDataSource2" Height="50px" Width="125px" DefaultMode="Insert">
<Fields>
<asp:BoundField DataField="SiteName" HeaderText="SiteName" SortExpression="SiteName" />
<asp:BoundField DataField="Trinome" HeaderText="Trinome" SortExpression="Trinome" />
<asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
<asp:BoundField DataField="floor" HeaderText="floor" SortExpression="floor" />
<asp:BoundField DataField="PostCode" HeaderText="PostCode" SortExpression="PostCode" />
<asp:BoundField DataField="Primary_Onsite_Contact" HeaderText="Primary_Onsite_Contact"
SortExpression="Primary_Onsite_Contact" />
<asp:BoundField DataField="Primary_Onsite_Contact_Number" HeaderText="Primary_Onsite_Contact_Number"
SortExpression="Primary_Onsite_Contact_Number" />
<asp:BoundField DataField="Secondary_Onsite_Contact" HeaderText="Secondary_Onsite_Contact"
SortExpression="Secondary_Onsite_Contact" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
SortExpression="ID" />
<asp:BoundField DataField="Secondary_Onsite_Contact_Number" HeaderText="Secondary_Onsite_Contact_Number"
SortExpression="Secondary_Onsite_Contact_Number" />
<asp:CommandField ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:EMCServerlistLatest %>"
DeleteCommand="DELETE FROM [SIRIUS_Contacts] WHERE [ID] = ?" InsertCommand="INSERT INTO [SIRIUS_Contacts] ([SiteName], [Trinome], [Address], [floor], [PostCode], [Primary_Onsite_Contact], [Primary_Onsite_Contact_Number], [Secondary_Onsite_Contact], [ID], [Secondary_Onsite_Contact_Number]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
ProviderName="<%$ ConnectionStrings:EMCServerlistLatest.ProviderName %>" SelectCommand="SELECT * FROM [SIRIUS_Contacts] WHERE ([Trinome] LIKE '%' + ? + '%')"
UpdateCommand="UPDATE [SIRIUS_Contacts] SET [SiteName] = ?, [Trinome] = ?, [Address] = ?, [floor] = ?, [PostCode] = ?, [Primary_Onsite_Contact] = ?, [Primary_Onsite_Contact_Number] = ?, [Secondary_Onsite_Contact] = ?, [Secondary_Onsite_Contact_Number] = ? WHERE [ID] = ?">
<DeleteParameters>
<asp:parameter Name="ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="SiteName" Type="String" />
<asp:parameter Name="Trinome" Type="String" />
<asp:parameter Name="Address" Type="String" />
<asp:parameter Name="floor" Type="String" />
<asp:parameter Name="PostCode" Type="String" />
<asp:parameter Name="Primary_Onsite_Contact" Type="String" />
<asp:parameter Name="Primary_Onsite_Contact_Number" Type="String" />
<asp:parameter Name="Secondary_Onsite_Contact" Type="String" />
<asp:parameter Name="Secondary_Onsite_Contact_Number" Type="String" />
<asp:parameter Name="ID" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" Name="Trinome" PropertyName="Text" Type="String" />
</SelectParameters>
<InsertParameters>
<asp:parameter Name="SiteName" Type="String" />
<asp:parameter Name="Trinome" Type="String" />
<asp:parameter Name="Address" Type="String" />
<asp:parameter Name="floor" Type="String" />
<asp:parameter Name="PostCode" Type="String" />
<asp:parameter Name="Primary_Onsite_Contact" Type="String" />
<asp:parameter Name="Primary_Onsite_Contact_Number" Type="String" />
<asp:parameter Name="Secondary_Onsite_Contact" Type="String" />
<asp:parameter Name="ID" Type="Int32" />
<asp:parameter Name="Secondary_Onsite_Contact_Number" Type="String" />
</InsertParameters>
</asp:SqlDataSource>

</form>
 
This is the error message I get I hope its of help?

You tried to assign the Null value to a variable that is not a Variant data type.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: You tried to assign the Null value to a variable that is not a Variant data type.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[OleDbException (0x80004005): You tried to assign the Null value to a variable that is not a Variant data type.]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +177
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +194
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +56
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +105
System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +88
System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +392
System.Web.UI.WebControls.SqlDataSourceView.ExecuteInsert(IDictionary values) +405
System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) +68
System.Web.UI.WebControls.DetailsView.HandleInsert(String commandArg, Boolean causesValidation) +391
System.Web.UI.WebControls.DetailsView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +609
System.Web.UI.WebControls.DetailsView.OnBubbleEvent(Object source, EventArgs e) +87
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.DetailsViewRow.OnBubbleEvent(Object source, EventArgs e) +109
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +86
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +153
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +172
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4919




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42
 
It's hard to tell from the error, but it seems you are trying to assign a NULL to a variable that doesn't allow it. You will need to step through your code and see what values are being assigned to your parameters. I belive that is where the problem is.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top