Link to home
Start Free TrialLog in
Avatar of pkvasan
pkvasan

asked on

Create Table in MSSQL & VB 2005

Hi
i want to create as and when i enter new profile of a person iam using SQL's CREATE TABLE Query, but iam getting error can any one hel me to over come this


Private Sub CreatePerTable()
        Dim TableID As String
        TableID = TextPerID.Text
        Dim cn As New SqlConnection(DataConn)
        Dim cmd As New SqlCommand("create Table '" & TableID & "' (SLNO INT,NAME varchar(20))", cn)
        cn.Open()
        cmd.ExecuteNonQuery()
        MsgBox("Created Table", MsgBoxStyle.Information, "Confirmation")
        cn.Close()
    End Sub

Open in new window

Avatar of bigjokey
bigjokey

What is the error that you are getting?  For starters, I think you need to remove the single quotes from around the table name. If that doesn't help, are you using a User ID to connect to the database that doesn't have Create Table privilidges?
Avatar of pkvasan

ASKER

iam getting error saying Incorrect syntax near '110'.
110 is the value in TableID, i tried removing single quote but i still get the same error
no i dont use USER ID to connect DB

the same SQL Querry works fine when i use
"create Table Table1  (SLNO INT,NAME varchar(20))", but with passing variable as table name is giving this error
ASKER CERTIFIED SOLUTION
Avatar of the_bachelor
the_bachelor

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i think DB table doesnt allow the table name with the integer as the initial, try change the name of the table "110" to something like "T110", as long as it is a alphabet initial.
Avatar of pkvasan

ASKER

Thanks this worked