• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 465
  • Last Modified:

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

Hello,

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,
0
ZKM128
Asked:
ZKM128
  • 2
  • 2
1 Solution
 
Easwaran ParamasivamCommented:
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.
0
 
Alan WarrenCommented:
Does your DataSource know that you made that change?
You may need to re-configure your datasource...

Alan
0
 
ZKM128Author Commented:
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?
0
 
Alan WarrenCommented:
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

Alan
0
 
ZKM128Author Commented:
Thank you.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now