bri189a Posted March 24, 2004 Posted March 24, 2004 (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 March 24, 2004 by Derek Stone Quote
Administrators PlausiblyDamp Posted March 24, 2004 Administrators Posted March 24, 2004 if(typeof(o) is System.Int32) { //whatever } Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
bri189a Posted March 24, 2004 Author Posted March 24, 2004 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; } Quote
Administrators PlausiblyDamp Posted March 25, 2004 Administrators Posted March 25, 2004 Err, ignore the last post completely. Try the following as an example System.Data.SqlClient.SqlCommand o = new System.Data.SqlClient.SqlCommand(); if (o.GetType() == typeof(System.Data.SqlClient.SqlCommand)) { MessageBox.Show("Fing"); } Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
JABE Posted March 25, 2004 Posted March 25, 2004 This may also work: Select Case Type.GetTypeCode(Column[0].DataType) Case TypeCode.String '... Case TypeCode.Int16 '... End Select Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.