1

I want to pass the table as parameter for my sqlQuery . I have a lot of tables with the same colums but different values so it would be nice if the costumer could choose the table .

[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;


    }

And this is the Error i get back when i excecute it :

    <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>
  • 1
    Have you checked that the SQL generated was sane? – Rowland Shaw Apr 11 '16 at 16:02
  • check the type of your callerId, i think is the cause of error. – MNF Apr 11 '16 at 16:10
  • why you don't use stored procedure? it's more simple and clear. – MNF Apr 11 '16 at 16:14
  • No CallerId is not the problem because if i write my table in the statement en excute it it works . And i'm looking into stored procedures now :) – lesley belgium cuber houben Apr 11 '16 at 16:21
  • What does the debugger say `"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 +"'"` evaluates to? – Rowland Shaw Apr 12 '16 at 07:38

0 Answers0