? Create Table in VB.net

gmilsted

New member
Joined
Oct 14, 2004
Messages
2
Programming Experience
Beginner
I've written an sql statement within my vb.net page but I'm getting an error when I use the vb page

I want to write a page that allows the user to create a table within the database.

For example if I write pc24 in the textbox of the vb page i get the error...

Line 1: Incorrect syntax near 'pc24'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near 'pc24'.

Source Error:
Line 33: objDR = objCmd.ExecuteReader()



If I write the following statement it succeeds...
objCmd = New SqlCommand("CREATE TABLE pc24 (id int IDENTITY (1,...etc

However if I want to create a textbox that allows the user to specify there own table name I write the code like this...
objCmd = New SqlCommand("CREATE TABLE'" & strProductName & "'(id int IDENTITY (1...etc
It barfs about the text the user has entered into the text box, why should this matter?

Can anyone help?

Someone Please HELP!!!!
 
if you look at your code more precisely you'll see that the actual commandstring in the second example is

CREATE TABLE 'pc24' (id ... while the first is CREATE TABLE pc24 (id ... So why do you put single quotes in the second one????

try following: objCmd = New SqlCommand("CREATE TABLE " & strProductName & " (id int IDENTITY (1...etc
ALSO DON4T FORGET TO PU SPACES else the text will be CREATE TABLEpc24(id ...
 
Genius,

Thanks I've been stuck on that for a week now! Brilliant. Do you want an invitation to GMail to say thanks?

Greg.
 
Back
Top