关键字"Table" C#SQL附近的语法不正确 [英] Incorrect syntax near the keyword 'Table' C# SQL
本文介绍了关键字"Table" C#SQL附近的语法不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,我想弄清楚为什么我有这个错误
Hello I'm trying to figure out why i have this error
关键字"Table"附近的语法不正确.
Incorrect syntax near the keyword 'Table'.
提前谢谢
代码:
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();
}
}
}
}
服务器资源管理器:
推荐答案
发生这种情况是因为TABLE是为T-SQL保留的关键字.
如果您确实需要使用该名称,则查询应将TABLE括在方括号中
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
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 for the content of that table
这篇关于关键字"Table" C#SQL附近的语法不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文