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?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. styko

    Types returned by WebService

    styko, Aug 1, 2003, in forum: Microsoft C# .NET
    Replies:
    0
    Views:
    183
    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:
    338
    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:
    429
    Henrik Dahl
    Jul 6, 2004
  4. Laura T.
    Replies:
    3
    Views:
    412
    Laura T.
    Jul 15, 2004
  5. Axel Dahmen

    Types depending on other types

    Axel Dahmen, Aug 3, 2004, in forum: Microsoft C# .NET
    Replies:
    4
    Views:
    299
    Axel Dahmen
    Aug 4, 2004
  6. daniel

    Reference Types and Value Types

    daniel, Sep 2, 2004, in forum: Microsoft C# .NET
    Replies:
    19
    Views:
    414
    Champika Nirosh
    Oct 11, 2004
  7. RSH

    Checking for a null value in a datareader

    RSH, Jul 13, 2006, in forum: Microsoft C# .NET
    Replies:
    2
    Views:
    842
    sloan
    Jul 13, 2006
  8. JB
    Replies:
    4
    Views:
    2,504
Loading...