469,635 Members | 1,852 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,635 developers. It's quick & easy.

Strange NULL value behaviour / RequiredFieldValidator

Hi everyone,

Im puzzled by a NULL behaviour in SQL 2000 server.

There is a column in the table that does not allow NULL.

During data mining, the staff noted that, for that particular column, there
are a few records that are empty.

I do not specifically know whether they are "alt + 0160" character.

What are the reasons that can cause this to happen?
Validation front end, I've used ASP.NET's REQUIREDFIELDVALIDATOR on the
control to ensure that the field is compulsory

On the application scripting, I've the following to cleanse the data before
the data goes into the database:

cmd.Parameters.Add("@STREET_NAME", Data.SqlDbType.VarChar)
cmd.Parameters("@STREET_NAME").Value =
ReplaceSingleQuote(streetname.Text.Trim())

The function is:

Public Shared Function ReplaceSingleQuote(ByVal x As String)

If x = "" Then
Return x
End If

x = x.Replace("'", "''")
Return x

End Function

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Apr 5 '07 #1
4 1906
Howdy,

I see you're using Parameters so you don't need to replace any characters as
SqlParameter is responsible for that. It's only required if you build queries
through concatenation. I suspect all single quotes have been turned to doule
quotes (see it in the database). Anyway, it seems there's something wrong
with your validation as empty entries are submited.

Regards
--
Milosz
"Eric Layman" wrote:
Hi everyone,

Im puzzled by a NULL behaviour in SQL 2000 server.

There is a column in the table that does not allow NULL.

During data mining, the staff noted that, for that particular column, there
are a few records that are empty.

I do not specifically know whether they are "alt + 0160" character.

What are the reasons that can cause this to happen?
Validation front end, I've used ASP.NET's REQUIREDFIELDVALIDATOR on the
control to ensure that the field is compulsory

On the application scripting, I've the following to cleanse the data before
the data goes into the database:

cmd.Parameters.Add("@STREET_NAME", Data.SqlDbType.VarChar)
cmd.Parameters("@STREET_NAME").Value =
ReplaceSingleQuote(streetname.Text.Trim())

The function is:

Public Shared Function ReplaceSingleQuote(ByVal x As String)

If x = "" Then
Return x
End If

x = x.Replace("'", "''")
Return x

End Function

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Apr 5 '07 #2
Thanks for the reply.

That's very weird.

I have no idea how to account for the blank columns!

She showed me the sql commands and that column is specifically set to NOT
NULL

She asked me "How did you do that?"

"Milosz Skalecki [MCAD]" <mi*****@DONTLIKESPAMwp.plwrote in message
news:F8**********************************@microsof t.com...
Howdy,

I see you're using Parameters so you don't need to replace any characters
as
SqlParameter is responsible for that. It's only required if you build
queries
through concatenation. I suspect all single quotes have been turned to
doule
quotes (see it in the database). Anyway, it seems there's something wrong
with your validation as empty entries are submited.

Regards
--
Milosz
"Eric Layman" wrote:
>Hi everyone,

Im puzzled by a NULL behaviour in SQL 2000 server.

There is a column in the table that does not allow NULL.

During data mining, the staff noted that, for that particular column,
there
are a few records that are empty.

I do not specifically know whether they are "alt + 0160" character.

What are the reasons that can cause this to happen?
Validation front end, I've used ASP.NET's REQUIREDFIELDVALIDATOR on the
control to ensure that the field is compulsory

On the application scripting, I've the following to cleanse the data
before
the data goes into the database:

cmd.Parameters.Add("@STREET_NAME", Data.SqlDbType.VarChar)
cmd.Parameters("@STREET_NAME").Value =
ReplaceSingleQuote(streetname.Text.Trim())

The function is:

Public Shared Function ReplaceSingleQuote(ByVal x As String)

If x = "" Then
Return x
End If

x = x.Replace("'", "''")
Return x

End Function

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com


Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Apr 5 '07 #3
Hi Eric again,

Correct me if I’m wrong but you (or she) is confusing empty string with
NULL. NULL is a special value that simply indicates nothing is assigned,
whilst empty string is a correct value. Setting NOT NULL constraint to a
varchar column means NULL value is not allowed, but any other values (like
empty string '') are. Also check if there is a default value set for this
column. Anyway, from the code you posted, I suspect, there aren’t data access
layer or business logic layers as you assign values directly from user
controls. This may indicate, operations on the table are performed in several
places differently (different logic?). In addition, do you use stored
procedures or plain text queries? If SPs, please confirm there is no logic
inside that inserts empty string in some cases. And the last tip, have you
checked if there are any triggers created on this table?

Regards

--
Milosz

"Eric Layman" wrote:
Thanks for the reply.

That's very weird.

I have no idea how to account for the blank columns!

She showed me the sql commands and that column is specifically set to NOT
NULL

She asked me "How did you do that?"

"Milosz Skalecki [MCAD]" <mi*****@DONTLIKESPAMwp.plwrote in message
news:F8**********************************@microsof t.com...
Howdy,

I see you're using Parameters so you don't need to replace any characters
as
SqlParameter is responsible for that. It's only required if you build
queries
through concatenation. I suspect all single quotes have been turned to
doule
quotes (see it in the database). Anyway, it seems there's something wrong
with your validation as empty entries are submited.

Regards
--
Milosz
"Eric Layman" wrote:
Hi everyone,

Im puzzled by a NULL behaviour in SQL 2000 server.

There is a column in the table that does not allow NULL.

During data mining, the staff noted that, for that particular column,
there
are a few records that are empty.

I do not specifically know whether they are "alt + 0160" character.

What are the reasons that can cause this to happen?
Validation front end, I've used ASP.NET's REQUIREDFIELDVALIDATOR on the
control to ensure that the field is compulsory

On the application scripting, I've the following to cleanse the data
before
the data goes into the database:

cmd.Parameters.Add("@STREET_NAME", Data.SqlDbType.VarChar)
cmd.Parameters("@STREET_NAME").Value =
ReplaceSingleQuote(streetname.Text.Trim())

The function is:

Public Shared Function ReplaceSingleQuote(ByVal x As String)

If x = "" Then
Return x
End If

x = x.Replace("'", "''")
Return x

End Function

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Apr 5 '07 #4
Run a test to see if there are actually NULLs in that column. Run the
following query:

SELECT *
FROM MyTable
WHERE MyColumn IS NULL

If you return rows then you have some NULLs in there and we'll need to
investigate how you got NULLs into a non-nullable column. If no rows are
returned then the column does not contain NULLs, and you need to determine
how you got zero-length strings into the column if you're not expecting them
to be there. If zero-length strings are being stored but are not
acceptable, you can add a check constraint like the following to the column:

CHECK(LEN(MyColumn) 0)

"Eric Layman" <namyalcire[at no spam]gmail.comwrote in message
news:11*************@sp6iad.superfeed.net...
Thanks for the reply.

That's very weird.

I have no idea how to account for the blank columns!

She showed me the sql commands and that column is specifically set to NOT
NULL

She asked me "How did you do that?"

"Milosz Skalecki [MCAD]" <mi*****@DONTLIKESPAMwp.plwrote in message
news:F8**********************************@microsof t.com...
>Howdy,

I see you're using Parameters so you don't need to replace any characters
as
SqlParameter is responsible for that. It's only required if you build
queries
through concatenation. I suspect all single quotes have been turned to
doule
quotes (see it in the database). Anyway, it seems there's something wrong
with your validation as empty entries are submited.

Regards
--
Milosz
"Eric Layman" wrote:
>>Hi everyone,

Im puzzled by a NULL behaviour in SQL 2000 server.

There is a column in the table that does not allow NULL.

During data mining, the staff noted that, for that particular column,
there
are a few records that are empty.

I do not specifically know whether they are "alt + 0160" character.

What are the reasons that can cause this to happen?
Validation front end, I've used ASP.NET's REQUIREDFIELDVALIDATOR on the
control to ensure that the field is compulsory

On the application scripting, I've the following to cleanse the data
before
the data goes into the database:

cmd.Parameters.Add("@STREET_NAME", Data.SqlDbType.VarChar)
cmd.Parameters("@STREET_NAME").Value =
ReplaceSingleQuote(streetname.Text.Trim())

The function is:

Public Shared Function ReplaceSingleQuote(ByVal x As String)

If x = "" Then
Return x
End If

x = x.Replace("'", "''")
Return x

End Function

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Apr 6 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Phil | last post: by
3 posts views Thread by Bruno van Dooren | last post: by
6 posts views Thread by Edd Dawson | last post: by
17 posts views Thread by matevzb | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.