Question incorect syntax near ' '

abhinsawant

New member
Joined
Apr 14, 2011
Messages
2
Programming Experience
Beginner
i have query to create table. i give name to table from text box. but wen i put integer in text box it gives me error as "incorrect syntax near ' 4' ". here 4 is the value which i entered in text box.. my code is as follows

If con.State = ConnectionState.Open Then
con.Close()
End If
con = New SqlConnection("Server=SAWANT-PC\SQLEXPRESS;Database=PR;Trusted_Connection=True")
con.Open()
sqlq = "create table " & CInt(EmpID.Text) & " (myId INTEGER CONSTRAINT PKeyMyId PRIMARY KEY," + "myName CHAR(50), myAddress CHAR(255), myBalance FLOAT)"
cmd = New SqlCommand(sqlq, con)
Try
cmd.ExecuteNonQuery()
Catch ae As SqlException
MessageBox.Show(ae.Message())
End Try
 
Can you have a table in SQLExpress called just '4' ?
 
@InertiaM
if u see... i want that table should hav employe id as name..
and wen i create directly from sql manager.. i can create it wid just number 4... but wen i pass it in text box in vb.net it gives me error..
 
Try taking the exact text of your query that you are running from the immediate window and running it in query analyzer if it works there it should work through code. I would just add something like EMPNUM4 instead of just 4 that can get confusing and may clear up the problem.
 
I cannot think of any good reason that you would be creating a table named after an ID in the database. What you are trying to do is almost undoubtedly wrong. Please explain what you are actually trying to achieve and we can explain how best to achieve it.
 
Back
Top