I need to show my users some sql statements so they can visual inspect them. Maybe they will copy the statements to SSMS for further checking. Anyway, I want to use the SQLTextEditor and would like to format/beautify the SQL before showing it my user.
I thought I had it working but including the TOP keywords creates the error: "Invalid \"SELECT\" statement.\nUnexpected token \"100\" at line 1, pos 12."
How can I make this work? Here is my code:
internal void FormatSQL2()
string sqlformatted = "";
SQLFormattingOptions formattingoptions = new SQLFormattingOptions();
formattingoptions.KeywordFormat = KeywordFormat.UpperCase;
formattingoptions.DynamicIndents = false;
GenericSyntaxProvider syn = new GenericSyntaxProvider();
ActiveQueryBuilder.View.WinForms.QueryBuilder qb = new ActiveQueryBuilder.View.WinForms.QueryBuilder();
qb.SyntaxProvider = syn;
qb.SQLFormattingOptions = formattingoptions;
//qb.SQL = "SELECT LOC_ID FROM TABLEX WHERE ID = 100"; //works
qb.SQL = "SELECT TOP 100 LOC_ID FROM TABLEX WHERE ID = 100"; //does not work...causes error
sqlformatted = qb.FormattedSQL;
sqlTextEditor1.Text = sqlformatted;
catch (Exception ex)
Please sign in to leave a comment.