By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,552 Members | 905 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,552 IT Pros & Developers. It's quick & easy.

from db to textbox

P: n/a
hey all,

when i pull a null value from a field in a database and try to put it in a
text box i get the following error:
Cast from type 'DBNull' to type 'String' is not valid.

How is this normally handled?

thanks,
rodchar
Nov 21 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
It depends on how you are getting the database value, but this should work
for you.

If TypeOf value Is DBNull Then
textbox1.value = ""
Else
textbox1.value = value
End If

--
Jonathan Allen
"rodchar" <ro*****@discussions.microsoft.com> wrote in message
news:62**********************************@microsof t.com...
hey all,

when i pull a null value from a field in a database and try to put it in a
text box i get the following error:
Cast from type 'DBNull' to type 'String' is not valid.

How is this normally handled?

thanks,
rodchar

Nov 21 '05 #2

P: n/a
ML
Check for null before setting the value of the textbox.

isdbnull

"rodchar" <ro*****@discussions.microsoft.com> wrote in message
news:62**********************************@microsof t.com...
hey all,

when i pull a null value from a field in a database and try to put it in a
text box i get the following error:
Cast from type 'DBNull' to type 'String' is not valid.

How is this normally handled?

thanks,
rodchar

Nov 21 '05 #3

P: n/a
"rodchar" <ro*****@discussions.microsoft.com> schrieb:
when i pull a null value from a field in a database and try to put it in a
text box i get the following error:
Cast from type 'DBNull' to type 'String' is not valid.


'DBNull.Value.ToString' will return an empty string.

\\\
Me.TextBox1.Text = bla.ToString()
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4

P: n/a
ML
Or you can always use the old empty string trick:
txtItem.Text = ds.Tables(0).Rows(0).Item("MyItem") & ""

"ML" <sc******@accesswave.ca> wrote in message
news:Ov**************@TK2MSFTNGP09.phx.gbl...
Check for null before setting the value of the textbox.

isdbnull

"rodchar" <ro*****@discussions.microsoft.com> wrote in message
news:62**********************************@microsof t.com...
hey all,

when i pull a null value from a field in a database and try to put it in
a
text box i get the following error:
Cast from type 'DBNull' to type 'String' is not valid.

How is this normally handled?

thanks,
rodchar


Nov 21 '05 #5

P: n/a
Rodchar,

How do you get a field direct from a database in a textbox, without
something as a dataset or a datareader.

When it is a dataset is normally binding used.

Cor
Nov 21 '05 #6

P: n/a
how about if you wanted to go the other way, if the user left the textbox
blank but you want to store null back in the database?

"rodchar" wrote:
hey all,

when i pull a null value from a field in a database and try to put it in a
text box i get the following error:
Cast from type 'DBNull' to type 'String' is not valid.

How is this normally handled?

thanks,
rodchar

Nov 21 '05 #7

P: n/a
ML
Are you using bound controls or how are you updating the data?

"rodchar" <ro*****@discussions.microsoft.com> wrote in message
news:64**********************************@microsof t.com...
how about if you wanted to go the other way, if the user left the textbox
blank but you want to store null back in the database?

"rodchar" wrote:
hey all,

when i pull a null value from a field in a database and try to put it in
a
text box i get the following error:
Cast from type 'DBNull' to type 'String' is not valid.

How is this normally handled?

thanks,
rodchar

Nov 21 '05 #8

P: n/a
using data adapter and dataset

"ML" wrote:
Are you using bound controls or how are you updating the data?

"rodchar" <ro*****@discussions.microsoft.com> wrote in message
news:64**********************************@microsof t.com...
how about if you wanted to go the other way, if the user left the textbox
blank but you want to store null back in the database?

"rodchar" wrote:
hey all,

when i pull a null value from a field in a database and try to put it in
a
text box i get the following error:
Cast from type 'DBNull' to type 'String' is not valid.

How is this normally handled?

thanks,
rodchar


Nov 21 '05 #9

P: n/a
Rodchar,

Than use databinding, I have just made a little sample for that

http://groups-beta.google.com/group/...2135ad3b?hl=en

I hope this helps,

Cor
Nov 21 '05 #10

P: n/a
thank you very much for everyone's help.

"Cor Ligthert" wrote:
Rodchar,

Than use databinding, I have just made a little sample for that

http://groups-beta.google.com/group/...2135ad3b?hl=en

I hope this helps,

Cor

Nov 21 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.