Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Im getting this error on compile

 

Cast from type 'DBNull' to type 'String' is not valid

 

I insert this:

 

If IsDBNull(txt_subcode.Text) Then
           txt_subcode.Text = ""
       End If

 

to try to use a blank but it didnt read in either.

 

How do I allow for a blank/NULL in a string text variable/textbox?

Posted

DBNull, as the name represents it's only for Data Base use only!

 

Is this what you're looking fo?:

 

Me.TextBox1.Text = Nothing

 

 

If not, ty to explain better your problem ok?

I'll be here to help... :D

 

 

 

Alex :D

Software bugs are impossible to detect by anybody except the end user.
Posted

Yes i am working with an ACCESS2000 database.

 

What I am trying to do is have TWO comboboxes.

 

The first one will choose something and the second one chooses a subcode. For example Project name 001

 

I have make my database already.

 

In the jobs table i have a field called subcode (which is linked to the subcode table)

 

jobs Table: subcode Table:

JobsID SubcodeID

JobsDesc subcode

JobsSubcode

.

.

.etc

 

In the jobs table you have to kinda select from the subcode field which is a combobox that contains all the fields from the subcode field.

 

However, the subcode field is empty when it starts. The user will pick the subcode to go with the jobDesc when the application loads.

 

I believe this is where the error is because that's where the error reads.

 

 

Thanks..

 

 

 

~~ Keroleen ~~

Posted

I had the same problem.

 

You need to check the contents of the database field before you copy it into your text box

 

if(IsDBNull(databasefield) then

txt_subcode.Text = ""

Else

txt_subcode.Text = databasefield

End if

 

I ended up making a function to do this.

Posted

Thanks.....I tried that but i still got the same error:

 

 

An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll

 

Additional information: Cast from type 'DBNull' to type 'String' is not valid.

 

i tried using

 


Dim drw2 As DataRow = DsJobs1.Tables("tblJobs").Rows(jobDescription)

If (IsDBNull(jobDescription)) Then
           txt_description.Text = ""
       Else
           txt_description.Text = drw2("jobDescription")
       End If

 

 

The Error occurs at txt_description.Text = drw2("jobDescription")

Posted

PS.

 

For initialization...if i use DataColumn rather than DataRow

 

 

Dim drw2 As DataColumn = DsJobs1.Tables("tblJobs").columns("jobDescription")

 

Rather than

 

Dim drw2 As DataRow = DsJobs1.Tables("tblJobs").rows(jobDescription)

 

seems to get rid of the error but still dont have desirable results.

 

 

Is there something i need to do with the database to separate the two comboBoxes.

I deleted the relationship between then so that my tblSubCode is now orphaned without any relationships to it. But its still linking the subcode to the projectname (when by chance i can get that far).

 

I need it so that the user must choose a project name and a corresponding subcode individually.

Posted

Not sure if this is what you need as I have not started to use ADO.NET yet (Still using ADO) but I am starting to learn it from a book.

 

It talks about NULL values and how to check for them, It says to use the following

 

If drw2.IsNull("jobDescription") then
....
else
....
End If

 

Hope This Helps.

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...