ADO/ADO.NET - Create table on existing data base

Asked By rooja moghtadaee on 27-Feb-06 03:12 AM
how to create or add new table on  existing database,at run time with ado.net 1 ?
in vb.net 2003 or 2005? 
pease help me .
with best regards .

Sample Code - Asked By drammer _ on 27-Feb-06 03:35 AM

Here's one by mv ark http://www.eggheadcafe.com/forums/ForumPost.asp?ID=60547&INTID=2

I forgot the example I gave so I created a new one[CODE]
Dim cmdX As New SqlCommand("", New SqlConnection("Integrated Security=SSPI;Initial Catalog=yourDB;Data Source=localhost;"))
Dim sSQL As String

With cmdX
   sSQL = "CREATE TABLE YourTable (Id INTEGER CONSTRAINT PKeyMyId PRIMARY KEY," & _
                "NameX CHAR(50), Desc CHAR(255), Amount FLOAT)"
   .CommandType = CommandType.Text
   .CommandText = sSQL
   .Connection.Open()
   .ExecuteNonQuery()
   .Connection.Close()
End With[/CODE]

Create table - Asked By Shallu Gupta on 27-Feb-06 03:39 AM

You can create table using ADO.Net in the same way as if you are executing a Stored Procedure.. Using ExecuteNonQuery..

[CODE]
mycon.ConnectionString="Data Source=computer_name;initial catalog=Library; User Id= sa Password=;
mycon.Open();
mycon.CommandType=CommandType.Text;
mycon.CommandText="Create table tablename(col1 int, col2 varchar(10))";
mycon.ExecuteNonQuery();
[/CODE]

FOr More Information Refer this Link..

http://www.codeproject.com/useritems/adodotnetprogrammatically.asp