Click here to Skip to main content
11,798,546 members (68,355 online)
Rate this: bad
Please Sign up or sign in to vote.
Hello Guys,
morning, i got stuck with of the freaking problem i.e. am using 4 (VS 2010) and Mysql(5.5)
for one of My project. created three tables in Mysql and connected it to .Net via server explorer
now i can see those three tables , please note have not written any code till now but as soon as i right click on table name and click refresh suddenly i get a error box saying
"Unable to cast object of type System.DbNull to System.string" and please not the sample DB code how i created my table

CREATE TABLE admintable( adminid int NOT NULL primary key,
password varchar(30));

here is the image <img src="" alt="" title="Hosted by" />
this is one table which i have mentioned here, please any out there help me to resolve this as am running out of time please
Posted 21-Apr-13 19:55pm
Sergey Alexandrovich Kryukov at 22-Apr-13 2:15am
Well, who told you that you can case one into another? Check the data for DbNull before casting to anything.
rmksiva at 22-Apr-13 2:19am
May i know, do you want create table by code or using server explorer ?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

It is a quite common problem, because DBNull and Null basically mean the same, but are not the same type.
There is a good thread[^] which should help you how you can resolve this.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 CPallini 585
1 Maciej Los 395
2 OriginalGriff 348
3 Abhinav S 257
4 phil.o 254
0 OriginalGriff 2,150
1 Maciej Los 1,790
2 KrunalRohit 1,456
3 CPallini 1,415
4 Richard MacCutchan 1,016

Advertise | Privacy | Mobile
Web03 | 2.8.151002.1 | Last Updated 22 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100