6 Replies - 4506 Views - Last Post: 11 April 2013 - 11:49 AM Rate Topic: -----

#1 BarNunBoi  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 232
  • Joined: 28-March 12

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

Posted 27 February 2013 - 01:17 PM

I am working on a legacy application that was built a couple years back....and for some reason one of the pages broke. Now please keep in mind Im not a guru when it comes to ASP.NET. I have a data grid/C1webgrid that I believe is giving me troubles. The reason I say that is sometimes I can access the page and all of my grids populate except for the very last one.

Now with said, I have checked my database and from what I can tell nothing looks null. I have search online for the error message, and I think I have an understanding as to what is happening. If Im not mistaken I am referencing a value of a datacolumn that is null. Now I am going to post my Stack Trace and then ask my question.

[InvalidCastException: Cast from type 'DBNull' to type 'Integer' is not valid.]
Microsoft.VisualBasic.CompilerServices.IntegerType.FromObject(Object Value) +819
ClientPortal.Team.GetSetUpData() +280
ClientPortal.Team.Page_Load(Object sender, EventArgs e) +612
System.Web.UI.Control.onload(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750


Now my question is this....is my error occurring at the GetSetUpData function. The reason I ask is because Im not the best when it comes to reading these stack traces. Also I wanted to post this and try find the answer on my own before I post any code. Thanks in advance!

Is This A Good Question/Topic? 0
  • +

Replies To: Cast from type 'DBNull' to type 'Integer' is not valid

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8939
  • View blog
  • Posts: 33,521
  • Joined: 12-June 08

Re: Cast from type 'DBNull' to type 'Integer' is not valid

Posted 27 February 2013 - 01:18 PM

Correct.. it's in ClientPortal.Team.GetSetUpData() +280 when called from here:
ClientPortal.Team.Page_Load(Object sender, EventArgs e) +612
Was This Post Helpful? 1
  • +
  • -

#3 BarNunBoi  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 232
  • Joined: 28-March 12

Re: Cast from type 'DBNull' to type 'Integer' is not valid

Posted 27 February 2013 - 01:31 PM

Kinda of a lame question but I have to ask because I don't know....what does +280 and +612 reference?
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8939
  • View blog
  • Posts: 33,521
  • Joined: 12-June 08

Re: Cast from type 'DBNull' to type 'Integer' is not valid

Posted 27 February 2013 - 01:39 PM

They are some compiler used offset.. nothing to be used by you and me..

Typically if you have 'debugging' turned on you can get the specific file and line number.
Was This Post Helpful? 1
  • +
  • -

#5 BarNunBoi  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 232
  • Joined: 28-March 12

Re: Cast from type 'DBNull' to type 'Integer' is not valid

Posted 27 February 2013 - 01:44 PM

Roger that!
Was This Post Helpful? 0
  • +
  • -

#6 albert018  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 22
  • Joined: 07-January 13

Re: Cast from type 'DBNull' to type 'Integer' is not valid

Posted 14 March 2013 - 09:53 AM

I suggest that you can check the following three points :

First: your code should look like this

DataTable.Rows[0][0]=DbNull.Value



Second: the property 「AllowDbNull」 in the datatable is 「true」

Third: to check that is there any comparison in the method 「GetSetUpData」? If it does. check whether the type is converted implicitly.

Just my simple thinkings.hope that it is helpful.
Was This Post Helpful? 1
  • +
  • -

#7 BarNunBoi  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 232
  • Joined: 28-March 12

Re: Cast from type 'DBNull' to type 'Integer' is not valid

Posted 11 April 2013 - 11:49 AM

I looked at my code and yes there is a line in there that is converting a Integer. That line of code is as follows.

 Dim RegionCode As Integer = CStr(ClientID)


Still not sure how to troubleshoot this thing. I checked my DB and I do allow nulls. Im going to try to hammer this thing out though. I will keep you guys posted.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1