0

Ist screenshot of error Second Error screenshot

My database is accepting null values which is against table definition. See snapshots. Is it possible? That 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.

3
  • Do SELECT * FROM student in a SQL Query Window. Do you see two records in there? I think you're just seeing a new record you could type in in the first snap shot. Commented Apr 25, 2011 at 18:30
  • Thanks. I didn't know (now i know) about empty and null string. Commented Apr 25, 2011 at 20:02
  • Would you edit your question (title) to be clearer about the question you're asking? Also, please replace "snapshot" with "screenshot", as snapshot is a very specific term, especially for SQL Server. Commented Apr 25, 2011 at 21:12

4 Answers 4

3

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.

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

4 Comments

The asterisk on the 'new' row indicates that all of the other rows listed have not been saved?
@Kenny Evitt: No. There is only ever one new row in the SSMS "open table" viewer
Oh! I assumed that the relevant row in the first screenshot ("snapshot") was the one with data! Did I mention that I avoid using that 'open table' window?
@Kenny Evitt: so do I... :-) I'd rather use MS Access he he he
1

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.

Comments

0

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.

Comments

0

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.

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.