Results 1 to 2 of 2

Thread: [RESOLVED] Error in casting a number

  1. #1

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Resolved [RESOLVED] Error in casting a number

    I hate to keep asking such newbie questions here, but...

    I have my data reader working. However, whenever I try to work with integer values from the database, I get this err:

    "When casting from a number, the value must be less than infinity"

    Code:
                    while (rdr.Read())
                    {
                        int shift = (int)rdr["shift"];
                        string shift2 = shift.ToString();
                        int empnum = (int)rdr["empnum"];
                        string empnum2 = empnum.ToString();
                        string namel = (string)rdr["namel"];
                        string namef = (string)rdr["namef"];
    
                        MessageBox.Show(shift2 + " " + empnum2 + " " + namel + "," + namef);
                    }
    It happens at

    int shift = (int)rdr["shift"];

    the string casting works fine...
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  2. #2

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Error in casting a number

    This worked

    Code:
                        string shift = null;
                        shift = rdr["shift"].ToString();
                        string empnum = null;
                        empnum = rdr["empnum"].ToString();
                        string namel = (string)rdr["namel"];
                        string namef = (string)rdr["namef"];
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width