Click here to Skip to main content
15,898,587 members
Please Sign up or sign in to vote.
1.89/5 (3 votes)
See more:
Ok i have problem



on this kind of sql command i have problem when i enter two word in textBox he is giving me error incorrect syntax near the second word when i have only one word he is creating the tables

What I have tried:

C#
SqlCommand comand = new SqlCommand("CREATE TABLE Dobavljaci_" +textBox.Text+ "(ID int NOT NULL identity(1,1) primary key,Naziv varchar(50),Sjediste varchar(50),Adresa varchar (50),Ziroracun varchar (50),sifra varchar(50),JIB varchar(50),Ulaz money,Izlaz money);", CON);


Can you help me please
Posted
Updated 28-Jun-17 15:22pm
v2

1 solution

Add [ ] (square brackets) around the name that has the space in it.

eg

CREATE TABLE [Dobavljaci_" +textBox.Text+ "](ID int NOT NULL ......
 
Share this answer
 
v2
Comments
Member 13084733 28-Jun-17 21:29pm    
Tnx for quick answer
Richard Deeming 29-Jun-17 17:43pm    
Now see what happens when a user types in something like: Apple ][ :)

Dynamically creating multiple tables with identical structures seems like an extremely bad database design.
RossMW 29-Jun-17 17:52pm    
Yes, I agree, but in reality, it all depends on the intent of information not supplied. My mind reading skills are not what Id like them to be...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900