String conversion for building select-where-clause (specific ODBC-Interface)

Hi,

I need to build a string with a string inside like:

"select * from %1 where %1.CalendarId == 'STANDARD' "

where value 'Standard' is value of a variable, see following code snippet

void selectCalendarData(string _calendarId)

{

// query

string axCapQuery = "select * from %1 where %1.CalendarId == %2";

StringBuilder sBQuery = new StringBuilder("select * from %1 where %1.CalendarId == ");

// Query building

sBQuery.Append(_calendarId);

...

}

but this gives me wrong string "select * from %1 where %1.CalendarId = Standard"

How can I convert and append variable to get 'Standard' as output.

Thanks,

Andrea



Answer this question

String conversion for building select-where-clause (specific ODBC-Interface)

  • Samyag1

    string tableName = "MyTable";
    string standardVariable = "Standard";

    string sBQuery = string.Format("select * from {0} where {0}.CalendarId == '{1}'", tableName, standardVariable);

    sbQuery will be filled with
    select * from MyTable where MyTable.CalendarId == 'Standard'



  • String conversion for building select-where-clause (specific ODBC-Interface)