Click here to Skip to main content
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 20: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)

Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 22 Apr 2013
Copyright © CodeProject, 1999-2014
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