Keroleen Posted December 2, 2003 Posted December 2, 2003 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? Quote
AlexCode Posted December 3, 2003 Posted December 3, 2003 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 Quote Software bugs are impossible to detect by anybody except the end user.
Keroleen Posted December 3, 2003 Author Posted December 3, 2003 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 ~~ Quote
pendragon Posted December 4, 2003 Posted December 4, 2003 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. Quote
Keroleen Posted December 9, 2003 Author Posted December 9, 2003 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") Quote
Keroleen Posted December 9, 2003 Author Posted December 9, 2003 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. Quote
pendragon Posted December 12, 2003 Posted December 12, 2003 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.