from db to textbox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
rodchar said:
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()
///
 
Or you can always use the old empty string trick:
txtItem.Text = ds.Tables(0).Rows(0).Item("MyItem") & ""
 
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
 
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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top