Results 1 to 6 of 6

Thread: Newbie to VB

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    4

    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

  2. #2
    Hyperactive Member danecook21's Avatar
    Join Date
    Feb 2008
    Location
    NC, USA
    Posts
    501

    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"

  3. #3
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: Newbie to VB

    Or put it in brackets [Test table]

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    4

    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

  5. #5
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    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)

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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
  •  



Click Here to Expand Forum to Full Width