2

I am successfully connecting to my sql 2008 server hosted on winhost.com. But I am following this tutorial: http://www.codeproject.com/KB/database/sql_in_csharp.aspx which was suggested in an answer from: Connecting to SQL Server Database C#-WinForms and I keep getting the exact same error when I try to:

  • Insert something into the table.
  • Retrieve something from the db.

The error is: "Incorrect syntax near the keyword 'table'.".

I don't know what's wrong. The error message is very vague, and everything seems to look fine.

I am using all the examples from the above tutorial, but they all give the same error.

Any suggestions? Does anyone have any other tutorials/articles for me I can have a look at?

Thank you

3 Answers 3

1

Where it says INSERT INTO table ... you have to change table to be the actual name of your table as it says in the text just beneath:

Now we will take a look at the values. table is simply the table within the database.

If you chose to call your table table then you can write [table] but it would be better to change the table name to something else.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. I don't know the name of my table. I just clicked on "Create Database" on the winhost.com site and then it gave me a connection string to use. And I have no way of looking "inside" the database. Would you by any chance have some sample code to create a table?
CREATE TABLE foo (bar INT); creates a table called foo with a column called bar of type INT.
Thank you Mark for your kind help. Much appreciated.
1

Where table appears in that tutorial, it's meant to be a 'placeholder' for an actual table name - table by itself is an illegal table name - hence the syntax error. If you need to use this name then [table] would be fine.

Comments

1

TABLE is a reserved word, try surrounding it with brackets, if you have created a table called table.

[table]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.