Click here to Skip to main content
15,913,090 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to work with generic date format Pin
PIEBALDconsult2-Aug-11 3:12
mvePIEBALDconsult2-Aug-11 3:12 
AnswerRe: How to work with generic date format Pin
Luc Pattyn2-Aug-11 16:58
sitebuilderLuc Pattyn2-Aug-11 16:58 
GeneralRe: How to work with generic date format Pin
PIEBALDconsult2-Aug-11 17:47
mvePIEBALDconsult2-Aug-11 17:47 
GeneralRe: How to work with generic date format Pin
PIEBALDconsult2-Aug-11 18:39
mvePIEBALDconsult2-Aug-11 18:39 
AnswerRe: How to work with generic date format Pin
Luc Pattyn3-Aug-11 4:41
sitebuilderLuc Pattyn3-Aug-11 4:41 
GeneralRe: How to work with generic date format Pin
PIEBALDconsult3-Aug-11 16:22
mvePIEBALDconsult3-Aug-11 16:22 
GeneralRe: How to work with generic date format Pin
Luc Pattyn3-Aug-11 16:59
sitebuilderLuc Pattyn3-Aug-11 16:59 
GeneralRe: How to work with generic date format [modified] Pin
PIEBALDconsult3-Aug-11 18:44
mvePIEBALDconsult3-Aug-11 18:44 
I dunno. I avoid wizards; I prefer to maintain control. On the other hand, the closest I've come to that was writing an app to create a clone of an Ingres database in SQL Server -- which had no keys and hardly any indices, so I didn't bother copying them.

Of course, I also avoid "Autonumber" fields, so you'll get little sympathy from me. Big Grin | :-D


Here's what I currently have for doing that sort of thing:

lang
protected virtual System.Collections.Generic.Dictionary<System.Type,System.String> TypeMap { get ; set ; }

...

public virtual int
CreateTable
(
    string                  TableName
,
    System.Data.IDataReader SchemaSource
)
{
    return ( this.CreateTable ( TableName , SchemaSource.GetSchemaTable() ) ) ;
}

public virtual int
CreateTable
(
    string                TableName
,
    System.Data.DataTable SchemaSource
)
{
    if ( this.TypeMap == null )
    {
        throw ( new System.InvalidProgramException ( "You can't translate without a TypeMap" ) ) ;
    }

    System.Text.StringBuilder cmd = new System.Text.StringBuilder() ;

    cmd.AppendFormat ( "CREATE TABLE [{0}] ( " , TableName ) ;

    foreach
    (
        System.Data.DataRow col
    in
        SchemaSource.Rows
    )
    {
        if ( !this.TypeMap.ContainsKey ( (System.Type) col [ "DataType" ] ) )
        {
            throw ( new System.InvalidProgramException
                ( "The TypeMap doesn't contain type " + col [ "DataType" ].ToString() ) ) ;
        }

        cmd.AppendFormat
        (
            this.TypeMap [ (System.Type) col [ "DataType" ] ]
        ,
            col [ "ColumnName" ]
        ,
            col [ "ColumnSize" ]
        ,
            col [ "NumericPrecision" ]
        ,
            col [ "NumericScale" ]
        ,
            (bool) col [ "AllowDBNull" ]?" NULL ":" NOT NULL "
        ) ;

        cmd.Append ( " , " ) ;
    }

    cmd.Replace ( "," , ")" , cmd.Length - 2  , 1 ) ;

    return ( this.ExecuteNonQuery ( cmd.ToString() ) ) ;
}


I know I've used this method, but only to clone tables from SQL Server to Access, so I'm unsure if it will work the other way.

Here's the TypeMap I have for Access:

typemap = new System.Collections.Generic.Dictionary<System.Type,System.String>() ;

typemap [ typeof(System.String)   ] = " [{0}] TEXT({1}) " ;
typemap [ typeof(System.Boolean)  ] = " [{0}] YESNO " ;
typemap [ typeof(System.Int32)    ] = " [{0}] INT " ;
typemap [ typeof(System.DateTime) ] = " [{0}] DATETIME " ;
typemap [ typeof(System.Guid)     ] = " [{0}] UNIQUEIDENTIFIER " ;


I hope it helps, or at least makes you laugh. I picture Hercule ROTFLMAOing. Big Grin | :-D

modified on Thursday, August 4, 2011 12:52 AM

GeneralRe: How to work with generic date format Pin
Richard Deeming11-Jan-12 5:44
mveRichard Deeming11-Jan-12 5:44 
QuestionRegEx with < or > Pin
econner1-Aug-11 9:55
econner1-Aug-11 9:55 
AnswerRe: RegEx with Pin
PIEBALDconsult1-Aug-11 14:45
mvePIEBALDconsult1-Aug-11 14:45 
AnswerRe: RegEx with Pin
Peter_in_27801-Aug-11 17:18
professionalPeter_in_27801-Aug-11 17:18 
GeneralRe: RegEx with Pin
OriginalGriff1-Aug-11 21:31
mveOriginalGriff1-Aug-11 21:31 
GeneralRe: RegEx with Pin
econner3-Aug-11 4:38
econner3-Aug-11 4:38 
GeneralRe: RegEx with Pin
Peter_in_27803-Aug-11 13:04
professionalPeter_in_27803-Aug-11 13:04 
GeneralRe: RegEx with Pin
econner3-Aug-11 13:27
econner3-Aug-11 13:27 
GeneralRe: RegEx with [modified] Pin
Peter_in_27803-Aug-11 15:11
professionalPeter_in_27803-Aug-11 15:11 
GeneralRe: RegEx with Pin
econner3-Aug-11 15:32
econner3-Aug-11 15:32 
Questionprocessing ozf2 and ozf3 file with c#? Pin
Mohsen Shahindust1-Aug-11 4:11
Mohsen Shahindust1-Aug-11 4:11 
GeneralRe: processing ozf2 and ozf3 file with c#? Pin
David19871-Aug-11 5:10
David19871-Aug-11 5:10 
GeneralRe: processing ozf2 and ozf3 file with c#? Pin
Mohsen Shahindust1-Aug-11 5:17
Mohsen Shahindust1-Aug-11 5:17 
GeneralRe: processing ozf2 and ozf3 file with c#? Pin
David19871-Aug-11 5:24
David19871-Aug-11 5:24 
GeneralRe: processing ozf2 and ozf3 file with c#? Pin
Mohsen Shahindust1-Aug-11 5:31
Mohsen Shahindust1-Aug-11 5:31 
GeneralRe: processing ozf2 and ozf3 file with c#? Pin
Pete O'Hanlon1-Aug-11 5:38
mvePete O'Hanlon1-Aug-11 5:38 
GeneralRe: processing ozf2 and ozf3 file with c#? Pin
Mohsen Shahindust1-Aug-11 5:46
Mohsen Shahindust1-Aug-11 5:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.