Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have an if statement to check to see if a value in my datacolumn is null. If it is null then I set my variable equal to "", if the value in my datacolumn is not null then I assign its value to my string. There is only one problem when I attempt this. If the value is null, I get either an error message stating that null can not be "" or if I use the word null instead of "", I get the message that null is no longer used and to use System.DBNull, but when I try System.DbNull, it tells me that I can not use it this way. I have tried everything that I can think of. Does anyone have any ideas of how to check the datacolumn for a null?

 

Here is my code:

                   If drUpd("CustomerID") = "" Then
                       strCID = ""
                   Else
                       strCID = CStr(drUpd("CustomerID"))
                   End If

 

Thanks, Chester

____________________________________________

http://www.pophamcafe.com

I am starting a developers section, more tutorials than anything.

Posted

Okay thank, that works. Now that leads to my next problem. How do I set a parameter to dbnull? This is my next code:

 


If strCID = "" Then
prmUpdID.Value = dbnull
Else
prmUpdID.Value = strCID
End IF
[/Code]

 

However, as you probably already know, I can not use dbnull in this fashion. How can I set the Parameter Value to Null?

 

Thanks,

 

Chester

____________________________________________

http://www.pophamcafe.com

I am starting a developers section, more tutorials than anything.

Posted

Okay that works, but as with everything else it has led to another problem. Now I am getting a message that says the field can not be a zero length. My database alllows nulls. I set the parameter to allow nulls also with this statement:

 

      prmUpdReg = New OleDbParameter("@Region", Data.OleDb.OleDbType.Char, 15, "Region")
       prmUpdReg.IsNullable = True

 

Now I do not see why I am getting that message. everything should be set to allow nulls. Anyone else have any ideas?

 

Chester

____________________________________________

http://www.pophamcafe.com

I am starting a developers section, more tutorials than anything.

Posted
Now I am getting a message that says the field can not be a zero length.

Sounds like you're using an Access database. For some mystrious and obscure reason text fields in Access have two properties that (in my sense) have conflicting behaviour. AllowNull which defaults to true and AllowZeroLength which defaults to false....

I've always thought that null values have zero length, but I guess the makers of Access disagree.

Anyway, if you have access to the database, set AllowZeroLength to true for the indicated textfield, there is a way of doing it codewise too but I dare not to type how since I've only done it once or twice a couple of employers ago.

 

HTH

Kejpa

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...