关键字 "INTO" 附近的语法不正确

Incorrect syntax near the keyword "INTO"

这是导致错误的 insert 查询:

 public int Insert(User obj){

     string query = "INSERT IGNORE INTO tblUser(Name,Photo,Email,Password,Branch,Phone,Address,Authority,Recover_Email,Facebook_ID)  values(@name,@photo,@email,@pass,@branch,@phone,@addr,@auth,@re,@fbID) ";
     List<SqlParameter> lstp = new List<SqlParameter>();
     lstp.Add(new SqlParameter("@name", obj.Name));
     lstp.Add(new SqlParameter("@photo", obj.Photo));
     lstp.Add(new SqlParameter("@email", obj.Email));
     lstp.Add(new SqlParameter("@pass", obj.Password));
     lstp.Add(new SqlParameter("@branch", obj.Branch));
     lstp.Add(new SqlParameter("@phone", obj.Phone));
     lstp.Add(new SqlParameter("@addr", obj.Address));
     lstp.Add(new SqlParameter("@auth", obj.Authority));
     lstp.Add(new SqlParameter("@re", obj.Recovery_Email));
     lstp.Add(new SqlParameter("@fbID", obj.Facebook_ID));
     return DBUtility.ModifyData(query, lstp);
}

异常详细信息:

System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'INTO'

Table 定义:

CREATE TABLE [dbo].[tblUser] (
    [UserID]         INT           IDENTITY (1, 1) NOT NULL,
    [Name]           VARCHAR (100) NULL,
    [Photo]          VARCHAR (500) NULL,
    [Email]          VARCHAR (50)  NULL,
    [Password]       VARCHAR (500) NULL,
    [Branch]         VARCHAR (50)  NULL,
    [Phone]          VARCHAR (50)  NULL,
    [Address]        VARCHAR (500) NULL,
    [Recovery_Email] VARCHAR (100) NULL,
    [Facebook_ID]    VARCHAR (200) NULL,
    PRIMARY KEY CLUSTERED ([UserID] ASC)
);

如果需要,堆栈跟踪:

 [SqlException (0x80131904): Incorrect syntax near the keyword 'INTO'.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +1787814
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5341674
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +546
   System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +1693
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +275
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) +1421
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +177
   System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite) +208
   System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +163
   DataAccess.DBUtility.ModifyData(String query, List`1 lstParams) in c:\Users\ABHISHEK\Documents\Visual Studio 2013\Projects\InventoryManagement\DataAccess\DBUtility.cs:36
   BusinessLogic.UserLogic.Insert(User obj) in c:\Users\ABHISHEK\Documents\Visual Studio 2013\Projects\InventoryManagement\BusinessLogic\UserLogic.cs:30
   InventoryManagementSys.FacebookSync.AuthorizeUser() in c:\Users\ABHISHEK\Documents\Visual Studio 2013\Projects\InventoryManagement\InventoryManagementSys\FacebookSync.aspx.cs:83
   InventoryManagementSys.FacebookSync.Page_Load(Object sender, EventArgs e) in c:\Users\ABHISHEK\Documents\Visual Studio 2013\Projects\InventoryManagement\InventoryManagementSys\FacebookSync.aspx.cs:20
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
   System.Web.UI.Control.OnLoad(EventArgs e) +92
   System.Web.UI.Control.LoadRecursive() +54
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

AFAIK,你不能用 INSERT IGNORE 变成 SQL SERVER。如果您在 SQL SERVER 2008 onwards 上,则可以使用 MERGE 在行不存在时执行 INSERT,或执行 UPDATE。例如

MERGE
INTO    tmp_final dv
USING   tmp_holding_DataValue t
ON      t.dateStamp = dv.dateStamp
        AND t.itemId = dv.itemId
WHEN NOT MATCHED THEN
INSERT  (dateStamp, itemId, value)
VALUES  (dateStamp, itemId, value)

编辑:很明显,您正在针对 SQL 服务器执行,因为 SQL 服务器客户端特定类型和方法出现在您的堆栈跟踪中。

基于对问题和答案的评论:

您已获得 Microsoft's SQL Server RDBMS mixed up with Oracle's MySQL RDBMS。

使用SQL服务器时需要使用T-SQL(微软的SQL方言)。

使用MySQL时需要使用MySQL的SQL方言。

虽然可以编写同时使用两者的通用代码,但它要复杂得多(例如,您需要使用通用类型(如 DbCommand),以便大多数代码生成具有某种形式的正确具体类型工厂层)。

始终使用一个 RDBMS(更简单的选择)或构建基础架构(包括限制自己使用 SQL 方言的公共部分)以跨 RDBMS 工作。