1

我想将表作为参数传递给我的 sqlQuery 。我有很多具有相同列但值不同的表格,所以如果客户可以选择表格会很好。

[WebGet]
    public List<callersW> GetCallersByCallerIdF(string table ,string callerid)
    {

        testCDREntities1 context = this.CurrentDataSource;

        //SqlCommandBuilder cmdBuilder = new SqlCommandBuilder();
        // string tbName = cmdBuilder.QuoteIdentifier(table);

        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 "+ table +" where CallerId = '"+ callerid +"'").ToList();
        return result;


    }

这是我执行时返回的错误:

    <m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<m:code/>
<m:message xml:lang="nl-BE">Bad Request - Error in query syntax.</m:message>
    </m:error>
4

0 回答 0