|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
-->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 |
|
#3
|
||||
|
||||
|
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; |
![]() |
| Viewing: ASP Free Forums > Programming > .NET Development > Unable to cast object of type 'System.DBNull' to type 'System.String'. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|