WCF服务中的SQL查询的语法错误

时间:2016-04-08 12:58:10

标签: mysql sql wcf

当我尝试将表名作为这样的参数时出现语法错误:

[WebGet]
public List<callersW> GetCallersByCallerIdF(string callerid)
{
    testCDREntities1 context = this.CurrentDataSource;

    List<callersW> result = context.Database.SqlQuery<callersW>("SELECT CallerId,CalledID,Created, " + 
        " Answered,Destroyed,DisconnectionCode,RTP_Caller_G107MOS,RTP_Caller_LostPackets, " +
        " RTP_Caller_MaxRfc3550Jitter,RTP_Caller_MeanRfc3550Jitter,RTP_Called_G107MOS, " +
        " RTP_Called_LostPackets,RTP_Called_MaxRfc3550Jitter,RTP_Called_MeanRfc3550Jitter FROM TestTable where CallerId = '"+ callerid +"'").ToList();
    return result;
}

但如果我将其内联,那么它可以正常工作:

An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.Entity.dll but was not handled in user code

Additional information: Incorrect syntax near 'TestTable'.

这是错误:

photo = PhotoImage(...)

label = Label(image=photo)
label.image = photo # keep a reference!
label.pack()

1 个答案:

答案 0 :(得分:0)

您不必引用表名 - 在您的示例中,表名在第二个示例中指定为TestTable,但在第一个示例中它出现在'TestTable'。表名不应该用引号括起来。

如果您使用保留关键字作为表名,则应使用反引号括起表名,例如:

`TestTable`

请注意,单引号字符

请参阅文档 - 9.2 Schema object names

相关问题