0

I am getting this error

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

This is the code:

</asp:GridView>
    <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
        DataFile="~/videogames.accdb" 
        DeleteCommand="DELETE FROM [Table1] WHERE [ID] = ?" 
        InsertCommand="INSERT INTO [Table1] ( ID,Name, ScreenName, Age, Game, YearsPlaying) VALUES (?, ?, ?, ?, ?, ?)" 
        SelectCommand="SELECT * FROM [Table1]" 
        UpdateCommand="UPDATE [Table1] SET [Name] = ?, [ScreenName] = ?, [Age] = ?, [Game] = ?, [YearsPlaying] = ? WHERE [ID] = ?">
        <DeleteParameters>
            <asp:Parameter Name="ID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="ID" Type="Int32" />
            <asp:Parameter Name="Name" Type="String" />
            <asp:Parameter Name="ScreenName" Type="String" />
            <asp:Parameter Name="Age" Type="Int32" />
            <asp:Parameter Name="Game" Type="String" />
            <asp:Parameter Name="YearsPlaying" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="Name" Type="String" />
            <asp:Parameter Name="ScreenName" Type="String" />
            <asp:Parameter Name="Age" Type="Int32" />
            <asp:Parameter Name="Game" Type="String" />
            <asp:Parameter Name="YearsPlaying" Type="String" />
            <asp:Parameter Name="ID" Type="Int32" />
        </UpdateParameters>

I've been over this and I can not get it to work right. Can someone please help me? Thanks.

When I tried to delete the insert parameters with the Id it comes back with a different error.

1
  • 1
    Does that ID field happen to be an autoincrement field in your Access database? Meaning your INSERT will fail if you include it? Commented Nov 23, 2011 at 14:01

2 Answers 2

4

Remove the ID InsertParameter:

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

Change your InsertCommand:

InsertCommand="INSERT INTO [Table1] (Name, ScreenName, Age, Game, YearsPlaying) VALUES (?, ?, ?, ?,?)" 

Solution to the “You tried to assign the Null value to a variable that is not a Variant data type.” Exception

Sign up to request clarification or add additional context in comments.

Comments

3

It might be because in the insert you have the ID while it could be an Autonumeric in the database. Try removing it from the Insert Command. Good luck!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.