VB.Net and SQL Statements
-
I am about to start a new project that requires using SQL statements. Where as before, I concatanated my SQL statements within VB.net, is there a better way of doing this. I read in some articles that this is not good practice. Should I start using stored procedure methods or use string builder. Any user experiance would be appreciated What are the pros and cons of doing it my way or should I start doing it different or just continue as before.
-
I am about to start a new project that requires using SQL statements. Where as before, I concatanated my SQL statements within VB.net, is there a better way of doing this. I read in some articles that this is not good practice. Should I start using stored procedure methods or use string builder. Any user experiance would be appreciated What are the pros and cons of doing it my way or should I start doing it different or just continue as before.
You should use Procedures. Try googling Parameterized Queries.
Mike Lasseter
-
I am about to start a new project that requires using SQL statements. Where as before, I concatanated my SQL statements within VB.net, is there a better way of doing this. I read in some articles that this is not good practice. Should I start using stored procedure methods or use string builder. Any user experiance would be appreciated What are the pros and cons of doing it my way or should I start doing it different or just continue as before.
Stored procedures are often the best way to go, but you will be limited in how you can create your SQL statements. A stored procedure has to be able to be compiled when saved, which means the compiler needs to know the fields to retrieve/update and the criteria to use when exucuting the procedure. With highly dynamic SQL, this is often not an option. In short, use a stored procedure if possible. Another option is to create SQL views and call those to retrieve data. If you're going to process the views though (i.e. retrieve a subset of data from a view), wrap that code in a stored procedure if possible.
james commercial developer, author, speaker, dude. www.jamesfoxall.com