Sunday, March 25, 2012

create table and fields

I have maked this little code but dont know the way to insertt new table and fileds in database DATABASE01...

Private Sub Command1_Click()

Dim objConn As ADODB.Connection
Set objConn = New ADODB.Connection
objConn.ConnectionString = "driver={SQL Server};server=DVD377-14D9E48C\SQLEXPRESS;uid=;pwd=;database=master"
objConn.Open
objConn.Execute "CREATE DATABASE DATABASE01"

''''
'"CREATE table Mytable"
''''

''''
'"CREATE filed1" in text format
'"CREATE filed2" in text format
'"CREATE filed3" in text format
'"CREATE filed4" in date format(DD/MM/YYYY)

''''

objConn.Close

End Subu should not be creating a database from a front end code. however, to create tables open another connection object by another connection string using the newly created database name. and then use the "Create Table" SQL. Check BOL for syntax etc.

No comments:

Post a Comment