Unticking Allow Nulls in table design view doesn't prevent web ASP.NET form null value insert

Posted on 2012-09-09
Last Modified: 2012-09-10

I have created a simple ASP.NET webform for gathering students' registration data.
When students enter their personal details on the ASPX website, the registration data goes into the 'Students' table in MS SQL Server 2008 R2 express edition.
The 'Students' table has fields 'FirstName' and 'Surname' and I have UNTICKED 'Allow Nulls' option for these fields in order to prevent students from entering their registration data without entering their name.

Allow Nulls option unticked
However, strangely I still get some blank records without any data on it. The FirstName field and Surname field are blank and in fact the record doesn't have any data/text on any of its fields at all, although I have UNTICKED the 'Allow Nulls' option for the FirstName and Surname field in the table design view.

How could this happen?  ASPX online data entry error?

Thank you,
Question by:ZKM128
    LVL 16

    Expert Comment

    by:Easwaran Paramasivam
    Please look at the script of the table that you have created.

    Ensure that FirstName and Surname has NOT NULL constraint.

    There could be chance that while creating the table you could allow nulls. Then some records could be inserted. After that both could be set as NOT NULL.

    This is the one of the possibility.

    If you find junk data please do delete those rows and do ensure that NOT NULL is set for those columns.
    LVL 26

    Expert Comment

    by:Alan Warren
    Does your DataSource know that you made that change?
    You may need to re-configure your datasource...


    Author Comment

    Hmm,, I think I didn't really understand the difference between the Null and Zero lengh string in SQL Server table.
    I think the 'Students' table was getting empty records that are having Zero Length string values for all fields.

    I'm not sure what actually causes the error but I want to prevent 'Students' table from receiving records with zero length string in its fields via ASPX web registration form.

    How can I prevent 'Students' table from getting 'Zero length string' value records?
    LVL 26

    Accepted Solution

    Hi ZKM128,
    You could use a RequiredFieldValidator, give it an initial value of "" and it will not allow empty strings to be updated or inserted in the underlying table.

                  <asp:TextBox ID="FirstNameTextBox" runat="server" Text='<%# Bind("FirstName") %>' ToolTip="Please enter a first name of 50 characters or less for this student record." Width="100%" />
                  <asp:RequiredFieldValidator ID="rfvFirstName" runat="server" ControlToValidate="FirstNameTextBox"
                      ErrorMessage="<b>Required Field</b><br />A valid first name of 50 characters or less is required." InitialValue="" 
                      Font-Size="Smaller" ForeColor="#8B0000" ValidationGroup="StudentsEditValidate" Display="Dynamic" />

    Open in new window


    Author Closing Comment

    Thank you.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now