String conversion for building select-where-clause (specific ODBC-Interface)  
Author Message
Andrea Gramm





PostPosted: Visual C# General, String conversion for building select-where-clause (specific ODBC-Interface) Top

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



Visual C#16  
 
 
boban.s





PostPosted: Visual C# General, String conversion for building select-where-clause (specific ODBC-Interface) Top

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'