views:

26

answers:

3

Hi All,

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: http://stackoverflow.com/questions/3357374/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

+2  A: 

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.

Mark Byers
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?
lucifer
`CREATE TABLE foo (bar INT);` creates a table called foo with a column called bar of type INT.
Mark Byers
Thank you Mark for your kind help. Much appreciated.
lucifer
+2  A: 

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

[table]
Chris Diver
+2  A: 

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.

Will A
Thank you very much Will A
lucifer