Strange sql server issue. Taking null values while
Ist screenshot of error Second Error screenshot
My database is accepting null values which is against table definition. See snapshots. Is it possible? Th开发者_JAVA技巧at I define colums to be not null and they can take null values
I was entering data from asp.net form and have defined these values to be null on page load.
e.g. txtUser_id.Text =""; . . .
Only those values were stored which were not declared to be null see snap shot in above links.
The asterisk on the left means it is a new row that is not yet saved, which is when it will be validated against the table definition.
textbox.Text=""
is not a null value. It is an empty string. Inserting it to sql server is the same as saying Insert '' into...
The 'null' values in your first record are just empty strings. If you wish to reject empty strings, validate against String.IsNullOrEmpty(txtUser_id.Text)
on the C# side, or do validation against rtrim(ltrim([insertedValue]))
on the SQL side.
As @StriplingWarrior mentioned, the bottom line (all nulls) is just a place holder until additional records are inserted.
When "Editing" a table in SQL Server Management Studio, there is always a row showing NULL values at the bottom of your view. This row with NULL values does not actually exist yet in your database table. That's why there's a *
out to the left side. It is there for your convenience so that you can easily insert values. Once you enter the values, it will validate to make sure the columns are not NULL before actually inserting the values.
If you're referring to the empty values in the table's first row: empty is not that same as NULL. You have no constraint to prevent the entry of zero-length strings into these columns, and that's what has happened.
I would recommend not using whatever that 'open table' GUI is (I don't know the exact name). It's not clear whether your 'database' accepted NULL
values or whether those columns have an empty string value. Execute the following query in a 'query window' to tell for sure:
SELECT * FROM dbo.Student;
I'd also recommend not using the term 'snapshot' to refer to what is more commonly called a 'screenshot', only because 'snapshot' is a very specific term in SQL Server. [I initially thought you had posted a file containing a database snapshot instead of images!]
Your ASP.NET code may also be passing empty strings, as your example code seems to indicate.
精彩评论