Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Over the past month I've picked up a lot of things that should be doing differant. I'm making a general class for database operations. One that dynamically creates the commands, adapters, and sql... everything so far, so good... but one problem... to transpose my Column.DataType to OleDbType I have a function for. Basically I wanted to use the keyword to do something like the following:

 

public OleDbType GetOleDbType(object o)
{  
     if(o is System.Int32)
     {
          return OleDbType.Integer;
     }
     //and so on throughout the types...
}
public Blah()
{ 
     OleDbType = GetOleDbType(Column[0].DataType);       
}

And even though Column[0].DataType maybe System.Int32, it always shows up in the first function as System.RuntimeType or System.Runtime... can't remember which right now... so I've modified my function to:

 

if(o.ToString()== "System.Int32)
    return OleDbType.Integer

 

It's working for now...but that's horrible I think... the is keyword should work for something like this right? That is what it was designed for?

 

Thanks.

[edit]I added in C# code tags. -Derek[/edit]

Edited by Derek Stone
Posted

I tried that before... I get the following error:

The type or namespace name 'o' could not be found (are you missing a using directive or an assembly reference?)

 

code:

 if(typeof(o) is System.Int32)
             {
                 return OleDbType.Integer;
             }

Posted

This may also work:

 

       Select Case Type.GetTypeCode(Column[0].DataType)            
            Case TypeCode.String
            '...
           Case TypeCode.Int16
           '...
       End Select

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...