Checking for datareader returned types at runtime

Discussion in 'Microsoft C# .NET' started by Guest, Mar 24, 2006.

  1. Guest

    Guest Guest

    dr is a dataset, str1 is a string. How can I know the type inside the
    datareader field?
    I tried:

    if(dr.GetValue(n) is System.Int32)
    str1=Convert.ToString(dr.GetSqlInt32(n))
    else
    str1=dr.GetString(n)

    But the compiler warns the if is always false.
    Thanks in advance
     
    Guest, Mar 24, 2006
    #1
    1. Advertisements

  2. Guest

    Guest Guest

    Sorry, dr is a SqlDatareader

    "João Costa" wrote:

    > dr is a dataset, str1 is a string. How can I know the type inside the
    > datareader field?
    > I tried:
    >
    > if(dr.GetValue(n) is System.Int32)
    > str1=Convert.ToString(dr.GetSqlInt32(n))
    > else
    > str1=dr.GetString(n)
    >
    > But the compiler warns the if is always false.
    > Thanks in advance
     
    Guest, Mar 24, 2006
    #2
    1. Advertisements

  3. Guest

    Guest Guest

    I solved the problem with:
    if(rsAux.GetFieldType(n).FullName == "System.Int32" )


    "João Costa" wrote:

    > Sorry, dr is a SqlDatareader
    >
    > "João Costa" wrote:
    >
    > > dr is a dataset, str1 is a string. How can I know the type inside the
    > > datareader field?
    > > I tried:
    > >
    > > if(dr.GetValue(n) is System.Int32)
    > > str1=Convert.ToString(dr.GetSqlInt32(n))
    > > else
    > > str1=dr.GetString(n)
    > >
    > > But the compiler warns the if is always false.
    > > Thanks in advance
     
    Guest, Mar 24, 2006
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. styko

    Types returned by WebService

    styko, Aug 1, 2003, in forum: Microsoft C# .NET
    Replies:
    0
    Views:
    151
    styko
    Aug 1, 2003
  2. Rafael Veronezi

    Value Types and Reference Types

    Rafael Veronezi, Oct 28, 2003, in forum: Microsoft C# .NET
    Replies:
    1
    Views:
    211
    Jon Skeet [C# MVP]
    Oct 28, 2003
  3. Guest

    Convert from XSD types to/from .NET types

    Guest, Jul 6, 2004, in forum: Microsoft C# .NET
    Replies:
    2
    Views:
    323
    Henrik Dahl
    Jul 6, 2004
  4. RSH

    Checking for a null value in a datareader

    RSH, Jul 13, 2006, in forum: Microsoft C# .NET
    Replies:
    2
    Views:
    742
    sloan
    Jul 13, 2006
  5. JB
    Replies:
    4
    Views:
    2,338
Loading...

Share This Page