Create Table in SQL server (Visual basic.Net )

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi everyone,

Now I am using Visual Basic.net to write a program but having some
headaches. The situation is as follows:

I am using ODBC connection to connect one database( non-SQL server) , which
has over 20 tables and each table has lot of fields. My aim is to setup a
button, everytime when the button is clicked, the selected tables through
the ODBC connection will be copied to a SQL server 2000 ( Both the data and
table structure), which means a table will be created on SQL server and all
the data will be inserted accordingly. If the created table has already
existed on the SQL server 2000, a drop action will be done before creating.

Is there a simplest way to fulfill above aim in Visual Basic code? I am
trying to use SQL-DMO , but it is too tedious as I need to write the code to
setup each table structure and insert the data , which is too tedious .

Thanks in advanced.
Ben
 
You could try to generalize by creatingh the target tables by inspecting the
source tables.

This way you'll be ablt to use the same code for all tables (do you hardcode
for now the structure for each table ?)

Patrice
 
Hi Patrice,

Thanks for your reponse. I haven't started the code for each table yet . And
still looking for a better way . But it will be a really tough job to
create the structure table by table in code.
 
"Table by table" ? I meant the program could just inspect the source table
and create "automatically" the target table. Once done you'll just have to
call the same code for each table.

If you don't want to do that in VB.NET code you could :
- use SELECT INTO, it will create the target table and will fill. You 'll
likely still have though to add some more "details" (such as FK)
- if the structure is fixed you could use a "model" file or a SQL script to
create the DB

It's a bit hard to suggest something as I don"t really see what are your
requirements...





Patrice

--
 
Back
Top