c# database connection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • iulius

    #1

    c# database connection

    Hello,
    I get the follwing exception when I'm trying to read data from
    SqlDataReader object using GetString(0)
    method:System.I nvalidCastExcep tion: Specified cast is not valid. at
    System.Data.Sql Client.SqlDataR eader.GetSqlStr ing(Int32 i)!!
    If I replace 0 with other index (e.g 1) it's working !!! Why ?
  • Wouter Seye

    #2
    Re: c# database connection

    I think GetString(0) might be returning a null value,
    check with IsDBNull(0) ......

    hope this helps,
    Wouter


    "iulius" <iuliushide@yah oo.com> wrote in message
    news:92543d1c.0 307280504.54e02 4b@posting.goog le.com...[color=blue]
    > Hello,
    > I get the follwing exception when I'm trying to read data from
    > SqlDataReader object using GetString(0)
    > method:System.I nvalidCastExcep tion: Specified cast is not valid. at
    > System.Data.Sql Client.SqlDataR eader.GetSqlStr ing(Int32 i)!!
    > If I replace 0 with other index (e.g 1) it's working !!! Why ?[/color]


    Comment

    • Coder Coder

      #3
      Re: c# database connection

      Yeh,

      I think you should try

      if (!reader.IsDBNu ll (0)) {

      // and then if there are casting issues

      reader.GerValue (0); // returns an object


      }








      [color=blue]
      > Hello,
      > I get the follwing exception when I'm trying to read data from
      > SqlDataReader object using GetString(0)
      > method:System.I nvalidCastExcep tion: Specified cast is not valid. at
      > System.Data.Sql Client.SqlDataR eader.GetSqlStr ing(Int32 i)!!
      > If I replace 0 with other index (e.g 1) it's working !!! Why ?[/color]

      Comment

      Working...