Being a realistic guy, and based on past experience, I guess I need to put my sights on versions much further ahead to get anything incorporated into Visual Studio. Assuming Microsoft is still in business and Visual Studio still exists in 5 years, here is a clarification of a feature I’ve been asking for since VS 2000.
Please let developers right-click to “Insert SQL” anywhere in the code editor. As you know, inserting formatted SQL into a string is far more complex than simply typing SELECT * FROM Authors. Queries being prototyped in code (as many developers do) are best developed using an interactive editor and debugger like the Query Builder or SQL Server Management Studio’s query editor. They are often 5-50 lines long. Once the query is done, getting it into your application is far too time-consuming. As I have described many times, this implementation would simply add a right-mouse button click to say “Insert SQL” as appears when you’re editing a SP. The effect would be the same. You would be taken to a query builder window where you build the SQL and when you click “OK” the string is taken back to the application, and formatted to permit it to be stored in a string using whatever line-continuation/concatenation regimen is required. 90% of this code exists today in Visual Studio—IMHO it’s just a matter of hooking it up. The routines used by the Visual Studio data source designer to build the TableAdapter command strings is there—it’s all there behind the scenes.
No, I don’t advocate leaving SQL imbedded in the code. This means that it’s far more difficult to change the code once the schema changes. If the SQL is in a SP, your application might still need to be corrected, but this can be far easier than if you have to visit every string in the application looking for SQL or the code that generates it on the fly.
As an adjunct, it would be especially nice if the parser noted that there were parameter markers in the string and generated the Parameters collection as well.
If you want this feature too, comment here and I’ll pass this along to Microsoft at the upcoming summit.
