PC Review


Reply
Thread Tools Rate Thread

Adding null to VB.Net field

 
 
tshad
Guest
Posts: n/a
 
      12th Jan 2005
I am trying to update field and if nothing is in the .text field, I get an
error.

For example, if I have the following string:

Dim CommandText as String = "Update ftsolutions.dbo.Applicant set
salaryCurrent = @SalaryCurrent where applicantID = @applicantID"

with the following parameter:

.Add("@salaryCurrent",SqlDbType.Money).value = salaryCurrent.text

I will get an error if salaryCurrent.text has nothing in it.

I want to make the field null, if nothing is entered. Something like:

if salaryCurrent.text = ""
.Add("@salaryCurrent",SqlDbType.Money).value = Nthing
else
.Add("@salaryCurrent",SqlDbType.Money).value = salaryCurrent.text
end if

This doesn't work, but how would I make it work?

Thanks,

Tom.


 
Reply With Quote
 
 
 
 
William \(Bill\) Vaughn
Guest
Posts: n/a
 
      12th Jan 2005
Set your logic to assign
.... .Value = DBNULL.Value
when the TextBox is a null string.

See my article "Much ADO about Nothing"
http://www.betav.com/msdn_magazine.htm
for more info about nothing (and NULLs)
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

"tshad" <(E-Mail Removed)> wrote in message
news:%23w2QKuN%(E-Mail Removed)...
>I am trying to update field and if nothing is in the .text field, I get an
>error.
>
> For example, if I have the following string:
>
> Dim CommandText as String = "Update ftsolutions.dbo.Applicant set
> salaryCurrent = @SalaryCurrent where applicantID = @applicantID"
>
> with the following parameter:
>
> .Add("@salaryCurrent",SqlDbType.Money).value = salaryCurrent.text
>
> I will get an error if salaryCurrent.text has nothing in it.
>
> I want to make the field null, if nothing is entered. Something like:
>
> if salaryCurrent.text = ""
> .Add("@salaryCurrent",SqlDbType.Money).value = Nthing
> else
> .Add("@salaryCurrent",SqlDbType.Money).value = salaryCurrent.text
> end if
>
> This doesn't work, but how would I make it work?
>
> Thanks,
>
> Tom.
>



 
Reply With Quote
 
tshad
Guest
Posts: n/a
 
      12th Jan 2005
"William (Bill) Vaughn" <(E-Mail Removed)> wrote in message
news:OrAJJGO%(E-Mail Removed)...
> Set your logic to assign
> .... .Value = DBNULL.Value
> when the TextBox is a null string.


That was it.

Thanks,

Tom
>
> See my article "Much ADO about Nothing"
> http://www.betav.com/msdn_magazine.htm
> for more info about nothing (and NULLs)
> --
> ____________________________________
> William (Bill) Vaughn
> Author, Mentor, Consultant
> Microsoft MVP
> www.betav.com
> Please reply only to the newsgroup so that others can benefit.
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> __________________________________
>
> "tshad" <(E-Mail Removed)> wrote in message
> news:%23w2QKuN%(E-Mail Removed)...
>>I am trying to update field and if nothing is in the .text field, I get an
>>error.
>>
>> For example, if I have the following string:
>>
>> Dim CommandText as String = "Update ftsolutions.dbo.Applicant set
>> salaryCurrent = @SalaryCurrent where applicantID = @applicantID"
>>
>> with the following parameter:
>>
>> .Add("@salaryCurrent",SqlDbType.Money).value = salaryCurrent.text
>>
>> I will get an error if salaryCurrent.text has nothing in it.
>>
>> I want to make the field null, if nothing is entered. Something like:
>>
>> if salaryCurrent.text = ""
>> .Add("@salaryCurrent",SqlDbType.Money).value = Nthing
>> else
>> .Add("@salaryCurrent",SqlDbType.Money).value = salaryCurrent.text
>> end if
>>
>> This doesn't work, but how would I make it work?
>>
>> Thanks,
>>
>> Tom.
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access query with IIF statements is null for a field and not null pjo Microsoft Access Queries 3 12th Feb 2010 07:14 PM
Fill null fields from last record non-null in that field CS Microsoft Access 3 4th Jan 2008 08:39 AM
Adding a field with a Null-value Rolf Rosenquist Microsoft Access Form Coding 2 30th May 2006 12:58 AM
adding a null field to another field Microsoft Access Form Coding 2 19th Jan 2004 10:54 PM
Null result when combining null field with non-null field in ADP View Lauren Quantrell Microsoft Access Form Coding 8 17th Nov 2003 02:34 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:07 AM.