|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Null, DBNull, Nothing, VBNullstringI am coming over from VB 6, learning VB.NET. I have read and have in front of me, the language reference from the msdn, on; Behavior of Null has changed, Isdbnull function and isnothing function. However, I am still at a loss to know excatly what to do. When I check a control for a value, (before I send it to a field on a record in the database), and the user has not entered anything into that control, What do I check for? IsDBNULL, Isnothing, or vbnullstring, Len()=0, or all four? What do I put in a field that is going to the datbase, if the user didn't enter anything into the control? system.dbnull.value, or Nothing, or vbnullstring or "" When I get a field back from the database, what do I check for? IsDBNull, Isnothing, vbnullstring, Len()=zero? Thanks in Advance, Larry Larry wrote:
Show quoteHide quote > Hi all, Q. "When I check a control for a value, (before I send it to a field on a> > I am coming over from VB 6, learning VB.NET. > > I have read and have in front of me, the language reference from > the msdn, on; Behavior of Null has changed, Isdbnull function and > isnothing function. > > However, I am still at a loss to know excatly what to do. > > When I check a control for a value, (before I send it to a field on a > record > in the database), and the user has not entered anything into that > control, What do I check for? > IsDBNULL, Isnothing, or vbnullstring, Len()=0, or all four? > > What do I put in a field that is going to the datbase, if the user > didn't enter anything into the control? > > system.dbnull.value, or Nothing, or vbnullstring or "" > > When I get a field back from the database, what do I check for? > IsDBNull, Isnothing, vbnullstring, Len()=zero? > > > Thanks in Advance, > > Larry record in the database), and the user has not entered anything into that control, What do I check for?" A. This depends on the control. A Textbox returns String.Empty when it blank. Q. "What do I put in a field that is going to the datbase, if the user didn't enter anything into the control?" A. This depends on how you want to handle your system. You can send DBNull.Value if you want the value to be null, or you can send a default value in. Q. "When I get a field back from the database, what do I check for? IsDBNull, Isnothing, vbnullstring, Len()=zero?" A. If the database has a null value in it you have to check the value is dbnull.value before trying to assign it to a variable. EX: if Reader.GetString(0) is DBNull.Value then ... Hope it helps Chris Thank You Chris,
I appreciate your answer. Larry I Don't Like Spam wrote: Show quoteHide quote > Larry wrote: >> Hi all, >> >> I am coming over from VB 6, learning VB.NET. >> >> I have read and have in front of me, the language reference from >> the msdn, on; Behavior of Null has changed, Isdbnull function and >> isnothing function. >> >> However, I am still at a loss to know excatly what to do. >> >> When I check a control for a value, (before I send it to a field on a >> record >> in the database), and the user has not entered anything into that >> control, What do I check for? >> IsDBNULL, Isnothing, or vbnullstring, Len()=0, or all four? >> >> What do I put in a field that is going to the datbase, if the user >> didn't enter anything into the control? >> >> system.dbnull.value, or Nothing, or vbnullstring or "" >> >> When I get a field back from the database, what do I check for? >> IsDBNull, Isnothing, vbnullstring, Len()=zero? >> >> >> Thanks in Advance, >> >> Larry > > > Q. "When I check a control for a value, (before I send it to a field on a > record in the database), and the user has not entered anything into that > control, What do I check for?" > > A. This depends on the control. A Textbox returns String.Empty when it > blank. > > > Q. "What do I put in a field that is going to the datbase, if the user > didn't enter anything into the control?" > > A. This depends on how you want to handle your system. You can send > DBNull.Value if you want the value to be null, or you can send a default > value in. > > Q. "When I get a field back from the database, what do I check for? > IsDBNull, Isnothing, vbnullstring, Len()=zero?" > > A. If the database has a null value in it you have to check the value is > dbnull.value before trying to assign it to a variable. > EX: if Reader.GetString(0) is DBNull.Value then ... > > Hope it helps > Chris > Larry,
An placeholder for a not yet used value or object IS Nothing A DB object that is not filled can be tested with DBValue.null An empty instanced value can be tested with = Nothing while this works as well for a not instanced value (not an object) because it will be instanced direct to the base value. And then there are it seems thousand of otherways which are in fact other use of the same. String.empty, string = "" (prefered by the long time regulars in this newsgroup), ISDBNull It is VB.Net not C# do it in your organisation in the way as it fits the culture of your organisation the best. Cor Show quoteHide quote "Larry" <bl***@Blifff.com> schreef in bericht news:%23m830ehTGHA.5108@TK2MSFTNGP09.phx.gbl... > Hi all, > > I am coming over from VB 6, learning VB.NET. > > I have read and have in front of me, the language reference from > the msdn, on; Behavior of Null has changed, Isdbnull function and > isnothing function. > > However, I am still at a loss to know excatly what to do. > > When I check a control for a value, (before I send it to a field on a > record > in the database), and the user has not entered anything into that control, > What do I check for? > IsDBNULL, Isnothing, or vbnullstring, Len()=0, or all four? > > What do I put in a field that is going to the datbase, if the user didn't > enter anything into the control? > > system.dbnull.value, or Nothing, or vbnullstring or "" > > When I get a field back from the database, what do I check for? > IsDBNull, Isnothing, vbnullstring, Len()=zero? > > > Thanks in Advance, > > Larry
VB.NET - Issues with VB.NET FTP Class to UNIX FTP Server
what's up? reading xml How do you know when all databindings on form are complete? Reading Excel in VB.NET SQL Distinct Create 30 Day trial version how to avoid broken references when give out projects Building VB.NET Interface definitions from a COM interface Process BUG? Opening a query in MS Access with parameters using VB.net |
|||||||||||||||||||||||