.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old May 8th, 2008, 05:22 AM
senzzor senzzor is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 2 senzzor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 30 sec
Reputation Power: 0
Unable to cast object of type 'System.DBNull' to type 'System.String'.

Greetings!

Im a beginning developer that is used of programming in vb,but now im working with C# and i have a horrible error thatis driving me crazy for days.

I have a basic detailsview for inserting, but when i insert , i get te following error :

Unable to cast object of type 'System.DBNull' to type 'System.String'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'System.String'.


Line 4947: get {
Line 4948: try {
Line 4949: return ((string)(this[this.tableEvenement.plaatsColumn]));
Line 4950: }
Line 4951: catch (global::System.InvalidCastException e) {





This is my BLL class :

public int InsertEvenement(String naam, String plaats, DateTime? datum,
string start,string einde, string status, int? populariteit, string expert,int? min,int? max, int? reserves)
{
//try
//{
CorePlanner.EvenementDataTable evenementen = new CorePlanner.EvenementDataTable();
CorePlanner.EvenementRow evenement = evenementen.NewEvenementRow();

evenement.naam = naam;


if (plaats == null) evenement.SetplaatsNull();
else evenement.plaats = plaats;


if (start == null) evenement.SetstartNull();
else evenement.start = start;

if (einde == null) evenement.SeteindeNull();
else evenement.einde = einde;

if (datum == null) evenement.SetdatumNull();
else evenement.datum = datum.Value;

if (min == null) evenement.SetminNull();
else evenement.min = min.Value;

if (max == null) evenement.SetmaxNull();
else evenement.max = max.Value;

if (reserves == null) evenement.SetreservesNull();
else evenement.reserves = reserves.Value;

evenement.status = status;


if (populariteit == null) evenement.SetpopulariteitNull();
else evenement.populariteit = populariteit.Value;

if (expert == null) evenement.SetexpertNull();
else evenement.expert = expert;


return Convert.ToInt32(Adapter.Inserteveneemnt (evenement.plaats, evenement.naam, evenement.expert, evenement.populariteit, evenement.status, evenement.einde, evenement.start, evenement.datum, evenement.min, evenement.max, evenement.reserves));




So if anyone could help, it would be wonderfull
Thnx

Senne Ceulemans

Reply With Quote
  #2  
Old May 8th, 2008, 06:06 AM
mehere's Avatar
mehere mehere is offline
Senior Sarcasm Wizardess
Click here for more information.
 
Join Date: Feb 2005
Location: Dreamland
Posts: 12,645 mehere User rank is General 8th Grade (Above 100000 Reputation Level)mehere User rank is General 8th Grade (Above 100000 Reputation Level)mehere User rank is General 8th Grade (Above 100000 Reputation Level)mehere User rank is General 8th Grade (Above 100000 Reputation Level)mehere User rank is General 8th Grade (Above 100000 Reputation Level)mehere User rank is General 8th Grade (Above 100000 Reputation Level)mehere User rank is General 8th Grade (Above 100000 Reputation Level)mehere User rank is General 8th Grade (Above 100000 Reputation Level)mehere User rank is General 8th Grade (Above 100000 Reputation Level)mehere User rank is General 8th Grade (Above 100000 Reputation Level)mehere User rank is General 8th Grade (Above 100000 Reputation Level)mehere User rank is General 8th Grade (Above 100000 Reputation Level)mehere User rank is General 8th Grade (Above 100000 Reputation Level)mehere User rank is General 8th Grade (Above 100000 Reputation Level)mehere User rank is General 8th Grade (Above 100000 Reputation Level)mehere User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 10976 Folding Title: Novice Folder
Time spent in forums: 4 Months 3 Weeks 5 Days 18 h 58 m 26 sec
Reputation Power: 1542
-->Thread moved to .NET Forum
__________________
Come JOIN the party!!!

Quote of the Month:
Stupidity: Quitters never win, winners never quit, but those who never win AND never quit are idiots.

Questions to Ponder:
If man evolved from monkeys and apes, why do we still have monkeys and apes?

iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
copyright© 2008 sbenj69

Reply With Quote
  #3  
Old May 9th, 2008, 04:31 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,608 Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 6th Grade (Above 100000 Reputation Level)  Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 4 Days 12 h 53 m 47 sec
Reputation Power: 1400
hi Senne,
you have message in plain English.
this value:
Code:
this[this.tableEvenement.plaatsColumn]

is NULL, thus can't be converted to string.
correct logic would be:
Code:
object oValue = this[this.tableEvenement.plaatsColumn];
if (oValue is System.DBNull)
   return null;
else
   return (string)oValue;
Comments on this post
lewy agrees!

Reply With Quote
Reply

Viewing: ASP Free ForumsProgramming.NET Development > Unable to cast object of type 'System.DBNull' to type 'System.String'.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway