Hello I'm trying to figure out why i have this error
你好,我想弄清楚为什么我有这个错误
Incorrect syntax near the keyword 'Table'.
关键字“Table”附近的语法不正确。
Thx in advance
Thx提前
Code :
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
namespace CSGObetsAdvisor
{
public class SQLInsertData
{
public void InsertToSQL(string LoungeItemName)
{
string connectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=" + @"C:\Users\HP\documents\visual studio 2013\Projects\CSGObetsAdvisor\CSGObetsAdvisor\App_Data\Database.mdf" + ";Integrated Security=True";
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand("INSERT INTO Table (ItemID,ItemName) VALUES (@ItemIDss,@Namess)");
cmd.CommandType = CommandType.Text;
cmd.Connection = connection;
cmd.Parameters.AddWithValue("@ItemIDss", 50);
cmd.Parameters.AddWithValue("@Namess", LoungeItemName);
connection.Open();
cmd.ExecuteNonQuery();
}
}
}
}
Server Explorer :
Server Explorer:
1 个解决方案
#1
5
That happens because TABLE is a reserved keyword for T-SQL.
If you really need to use that name, your query should enclose TABLE in square brackets
这是因为TABLE是T-SQL的保留关键字。如果确实需要使用该名称,则查询应将TABLE括在方括号中
SqlCommand cmd = new SqlCommand(@"INSERT INTO [Table]
(ItemID,ItemName) VALUES
(@ItemIDss,@Namess)");
I strongly suggest to change that name and use a more descriptive word of the content of that table
我强烈建议更改该名称,并使用该表内容的更具描述性的词语
#1
5
That happens because TABLE is a reserved keyword for T-SQL.
If you really need to use that name, your query should enclose TABLE in square brackets
这是因为TABLE是T-SQL的保留关键字。如果确实需要使用该名称,则查询应将TABLE括在方括号中
SqlCommand cmd = new SqlCommand(@"INSERT INTO [Table]
(ItemID,ItemName) VALUES
(@ItemIDss,@Namess)");
I strongly suggest to change that name and use a more descriptive word of the content of that table
我强烈建议更改该名称,并使用该表内容的更具描述性的词语