Re: convert DBNull to SqlInt32.Null by Mythran
Mythran
Wed Jul 28 11:06:53 CDT 2004
Yes, that is how I currently do it...just making the statement for the current
scenario though, since he/she/it is not using strongly typed datasets :)
Mythran
"Cowboy (Gregory A. Beamer) [MVP]" <NoSpamMgbworld@comcast.netNoSpamM> wrote in
message news:%239LfUpLdEHA.3512@TK2MSFTNGP12.phx.gbl...
> In most cases, I would use a Strongly Typed dataset, which would be more
> like so:
>
> if(!pomosna.TableName.IsColumnNameDbNull())
> {
> }
>
> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
>
> ************************************************
> Think Outside the Box!
> ************************************************
> "Mythran" <kip_potter@hotmail.com> wrote in message
> news:OQVBFmLdEHA.2544@TK2MSFTNGP10.phx.gbl...
> > The pure .Net way would be
> >
> > if (pomosna.Tables[0].Rows[0].IsNull("MaticenLekar"))
> > _MaticenLekar = SQLInt32.Null;
> > else
> > _MaticenLekar =
> Convert.ToInt32(pomosna.Tables[0].Rows[0]["MaticenLekar"]);
> >
> > :)
> >
> > Mythran
> >
> >
> > "Cowboy (Gregory A. Beamer) [MVP]" <NoSpamMgbworld@comcast.netNoSpamM>
> wrote in
> > message news:uqLbUILdEHA.592@TK2MSFTNGP11.phx.gbl...
> > > Run code like this:
> > >
> > > if(pomosna.Tables[0].Rows[0]["MaticenLekar"] == DbNull.Value)
> > > _MaticenLekar=SQLInt32.Null;
> > > else
> > >
> _MaticenLekar=Convert.ToInt32(pomosna.Tables[0].Rows[0]["MaticenLekar"]);
> > >
> > > --
> > > Gregory A. Beamer
> > > MVP; MCP: +I, SE, SD, DBA
> > >
> > > ************************************************
> > > Think Outside the Box!
> > > ************************************************
> > > "Vanja Andreev" <rusin@freemail.com.mk> wrote in message
> > > news:d7c210cb.0407280635.149753b5@posting.google.com...
> > > > have soure something like this
> > > >
> > > > private SqlInt32 _Licni_ID = SqlInt32.Null;
> > > > pomosna = new DataSet();
> > > > ...
> > > >
> _MaticenLekar=Convert.ToInt32(pomosna.Tables[0].Rows[0]["MaticenLekar"]);
> > > >
> > > > The application works OK except when "MaticenLekar" returns null when
> > > > i get error "Object cannot be cast from DBNull to other types."
> > > > i tryed all types of convert and non of them worked
> > > >
> > > > So my question is how to convert System.DBNull.Value to
> > > > System.Data.SqlTypes.SqlInt32.Null?
> > >
> > >
> >
> >
>
>