-
Newbie to VB
Hi all,
New to VB and just trying to create a table in a DB the script runs and doesnt error but table isnt created?? any ideas much appreciated
Dim objConnection, username, password, servername, databasename
servername = "Server"
databasename = "DB"
username = "user"
password = "password"
sub CreateDatabase
objConnection.Create _
"Provider=SQLOLEDB;Data Source=" & servername & ";" & _
"Trusted_Connection=Yes;Initial Catalog=" & databasename & ";" & _
"User ID=" & username & ";Password=" & password & ";"
objConnection.Execute "CREATE TABLE test table(" & _
"Year TEXT(4), " & _
"Month TEXT(9), " & _
"Day TEXT(2), " & _
"Time TEXT(25))"
End Sub
-
Re: Newbie to VB
Looks like you might have a syntax error. I do not work with SQL very often but I think it should look like "CREATE TABLE tablename (column1, column2, etc)"
So take out the second "table"
-
Re: Newbie to VB
Or put it in brackets [Test table]
-
Re: Newbie to VB
ok thanks for your help so far but test table just replaced the actual table name and is not the problem that seems to be the code??
Dim objConnection, username, password, servername, databasename
servername = "Server"
databasename = "DB"
username = "user"
password = "password"
sub CreateDatabase
objConnection.Create _
"Provider=SQLOLEDB;Data Source=" & servername & ";" & _
"Trusted_Connection=Yes;Initial Catalog=" & databasename & ";" & _
"User ID=" & username & ";Password=" & password & ";"
objConnection.Execute "CREATE TABLE testtable(" & _
"Year TEXT(4), " & _
"Month TEXT(9), " & _
"Day TEXT(2), " & _
"Time TEXT(25))"
End Sub
-
Re: Newbie to VB
This works on SQL 2000. You can't put a length on text.
CREATE TABLE testtable(Year TEXT, Month TEXT, Day TEXT, Time TEXT)
-
Re: Newbie to VB
Thread moved to Database Development forum
Which version of VB are you using? Your profile says you are using VB1, but the code implies you are using VBScript (which is different to VB).
Also, how have you set up objConnection? .Create is not a method that I am familiar with (it isn't supported by ADO)