Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Empty String to NULL

Status
Not open for further replies.

MarcusO

IS-IT--Management
Joined
Mar 28, 2001
Messages
13
Location
AU
Hello,

I am using SQL Server 2000 as database. When a user updates a record, let's say phone no, and just erases the value already stored, then VB.Net tries to store it as a zero-string. This doesn't work that well and SQL Server throws an error. Do I really have to check every value with if/then/else first to see if it is zero-string and if so convert it it NULL before running the update query?

Thanks,
Marcus
 
In a word, yes. How else is ADO.NET to know what you mean?

You can also do it in the stored procedure if you're using one.

If you're using a strongly typed dataset there is a method of the dataset that will set the the column to null that can be called if the string is zero length.



Bob Boffin
 
Or you can write one...

Code:
Public Shared Function CheckEmpty (value as string) as object
  if value = string.empty
    return dbnull.value
  else
    return value
  end if
end function

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Thanks for that. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top