Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 26th, 2014, 05:42 PM
Registered User
Points: 20, Level: 1
Points: 20, Level: 1 Points: 20, Level: 1 Points: 20, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2014
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Ch 13 - Inserting New Data

Ok, to preface this issue, I decided that I wanted to use a Microsoft Access DB file instead of setting up the SQL server just for simplicity purposes. I've been able to follow all the examples, up until now.

I created the AddEditReview.aspx page and coded it appropriately, but the problem I run into is adding a New entry, I get a "You tried to assign the Null value to a variable that is not a Variant data type" error message. If I enable the view for the ID field and manually type in the next available ID, it works just fine. Why isn't it taking the auto-number property of the field when creating the new entry and trying to pass a "null" value?

I know this isn't exactly to what is laid out in the book, but any help or push in the right direction would be appreciated... Thanks.

Also, I have ensured that the ID field in the Access DB is set properly: It is set to autonumber and it is unique.

Last edited by adkybe; January 26th, 2014 at 05:44 PM..
Reply With Quote
  #2 (permalink)  
Old January 26th, 2014, 05:48 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

Are you sure you set it to be an AutoNumber correctly? This:

Quote:
If I enable the view for the ID field and manually type in the next available ID, it works just fine
seems to imply it isn't.

Did you set it before you created the data controls? Can you post the code for the relevant controls on the page?

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old January 26th, 2014, 06:02 PM
Registered User
Points: 20, Level: 1
Points: 20, Level: 1 Points: 20, Level: 1 Points: 20, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2014
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well here is the link to a screen shot of my Access page with the ID field highlighted.

https://drive.google.com/file/d/0B11...it?usp=sharing

Here is the code for the page after creating all the controls:
Code:
<%@ Page Title="Planet Wrox - Management - Insert and Update Reviews" Language="C#" MasterPageFile="~/MasterPages/Management.master" AutoEventWireup="true" CodeFile="AddEditReview.aspx.cs" Inherits="Management_AddEditReview" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="ID" DataSourceID="SqlDataSource1" DefaultMode="Insert" Height="50px" Width="125px">
        <Fields>
            <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
            <asp:BoundField DataField="Summary" HeaderText="Summary" SortExpression="Summary" />
            <asp:BoundField DataField="Body" HeaderText="Body" SortExpression="Body" />
            <asp:BoundField DataField="GenreId" HeaderText="GenreId" SortExpression="GenreId" />
            <asp:CheckBoxField DataField="Authorized" HeaderText="Authorized" SortExpression="Authorized" />
            <asp:BoundField DataField="CreateDateTime" HeaderText="CreateDateTime" SortExpression="CreateDateTime" />
            <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
            <asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
        </Fields>
    </asp:DetailsView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" DeleteCommand="DELETE FROM [Review] WHERE [ID] = ?" InsertCommand="INSERT INTO [Review] ([Title], [Summary], [Body], [GenreId], [Authorized], [CreateDateTime], [ID]) VALUES (?, ?, ?, ?, ?, ?, ?)" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT [Title], [Summary], [Body], [GenreId], [Authorized], [CreateDateTime], [ID] FROM [Review] WHERE ([ID] = ?)" UpdateCommand="UPDATE [Review] SET [Title] = ?, [Summary] = ?, [Body] = ?, [GenreId] = ?, [Authorized] = ?, [CreateDateTime] = ? WHERE [ID] = ?">
        <DeleteParameters>
            <asp:Parameter Name="ID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="Title" Type="String" />
            <asp:Parameter Name="Summary" Type="String" />
            <asp:Parameter Name="Body" Type="String" />
            <asp:Parameter Name="GenreId" Type="Int32" />
            <asp:Parameter Name="Authorized" Type="Boolean" />
            <asp:Parameter Name="CreateDateTime" Type="DateTime" />
            <asp:Parameter Name="ID" Type="Int32" />
        </InsertParameters>
        <SelectParameters>
            <asp:QueryStringParameter Name="ID" QueryStringField="Id" Type="Int32" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="Title" Type="String" />
            <asp:Parameter Name="Summary" Type="String" />
            <asp:Parameter Name="Body" Type="String" />
            <asp:Parameter Name="GenreId" Type="Int32" />
            <asp:Parameter Name="Authorized" Type="Boolean" />
            <asp:Parameter Name="CreateDateTime" Type="DateTime" />
            <asp:Parameter Name="ID" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
</asp:Content>
Reply With Quote
  #4 (permalink)  
Old January 26th, 2014, 06:09 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

>> Well here is the link to a screen shot of my Access page with the ID field highlighted.

And how does its Design View look?

Question: why are you using Access? SQL Server is much more stable, and designed for a multi-user environment such as web sites, whereas Access isn't....

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #5 (permalink)  
Old January 26th, 2014, 06:21 PM
Registered User
Points: 20, Level: 1
Points: 20, Level: 1 Points: 20, Level: 1 Points: 20, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2014
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is the Design View:
https://drive.google.com/file/d/0B11...it?usp=sharing

I decided to use an Access file because I thought it was simpler. I began initially using SQL server 2012, but during my use, at some point kept getting an error message when I was trying to create the relationship, something about memory....Couldn't figure it out, tried a repair install of SQL and it seemed to mess it up more. I am also running this on a virtual machine just to keep it separate from my main system.

So, you can't upload the access file to a web server in the App_Data folder and it work like in the development environment?
Reply With Quote
  #6 (permalink)  
Old January 27th, 2014, 07:27 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

Sorry, I meant the Design View of the table in Access with the properties for the ID field.

>> So, you can't upload the access file to a web server in the App_Data folder and it work like in the development environment?

The answer is: it depends. Your host / server needs to support it, and you may have to install additional drivers to access the database. But even if you get it to work, you may still run into problems if your site has many visitors as Access isn't designed for a large number of concurrent users.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 13: TryItOut-Customizing Detail View --- not inserting new data? wgrayson BOOK: Beginning ASP.NET 4 : in C# and VB 7 September 4th, 2012 08:26 PM
Ch. 13 - PlanetWroxConnectionString1 hopper3011 BOOK: Beginning ASP.NET 4 : in C# and VB 6 August 27th, 2012 02:19 AM
another question in ch 13 nawar youssef BOOK: Beginning PHP 5.3 0 October 17th, 2011 12:40 AM
Ch 13-cms_articles_compose nuhbutt BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 1 June 1st, 2010 12:28 PM
Search ch 13, ch 16 sporik BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 0 October 27th, 2009 04:44 PM



All times are GMT -4. The time now is 06:07 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.