|
-
Jan 27th, 2009, 08:45 AM
#1
Thread Starter
New Member
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
-
Jan 27th, 2009, 08:56 AM
#2
Hyperactive Member
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"
-
Jan 27th, 2009, 09:01 AM
#3
Re: Newbie to VB
Or put it in brackets [Test table]
-
Jan 27th, 2009, 09:21 AM
#4
Thread Starter
New Member
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
-
Jan 27th, 2009, 11:54 AM
#5
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)
-
Jan 27th, 2009, 01:51 PM
#6
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)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|