convert .NET data types to SQL data types

  • Thread starter Thread starter Bamse
  • Start date Start date
B

Bamse

Hello all,

the job is the following:

given 2 databases I must recreate a table from one DB to another;

right now i'm using .getTableSchema, get a datatable with schema, loop
through all it's rows and build a "create table..." statement;

but the problems apear:
converting .NET types to sql types, column length mismatch (sql.text.16 ->
..Net.System.String.2147483647) which throws an exception.

Is there an elegant way of conversion?

Thank you,
Daniel
 
thank you, but the problem still remains...

in the table schema I have this column <column_name> of type System.String;
to which sql type do I convert it? text, char, varchar

as you know, the table schema contains only .NET data types that must be
converted to sql types.
 
Use GetSchemaTable I don't think you can if you need to match them exactly.
I misunderstood the end game. Why not use Information_Schema instead and or
write something on the DB side to do the recreation. If the two dbs can see
each other , this is cake. If they can't the pull the info down from
Information_Schema (will only work with SQL SErver) and grab it from there.
ie
Select * From INformation_Schema.Columns TableName. Then you can just fire
this with a reader or whatever and have the exact info you need.

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
http://www.devbuzz.com/content/zinc_personal_media_center_pg1.asp
 
Back
Top