Multiple line SQL string in VB.NET

It has been a while since I’ve had to write a rather long line in VB.NET and I forgot how to continue it on the following line so that it would not continue of the screen. My search on the web was fruitless (surprisingly), maybe I am a bad searcher, so I am writing this post.

Below is an example that will work on any long line of code that you wish to carry over to the next line.

I open Visual Studio 2005. This is an page with code included in the file.

 Visual Studio IDE

 An SQL query can get really complex and lengthy so breaking it out is easier. See the code below or the image.

Multiple Line Code - SQL string

strSQL = “Select cust_id, first_name, last_name, email, phone ” & _

“From customer01 ” & _

“Where email like ‘’

You may be programming a page that does not use code behind. Luckily for these pages you do not have to use the concatenating characters of “& _”.  As long as the SQL is within the quotes your page will work fine. See image below.

SQL Statement in inline Code

<asp:AccessDataSource ID=”AccessDataSource1″ runat=”server” DataFile=”~/App_Data/cust.mdb” SelectCommand=”SELECT [CUST_ID], [FIRST_NAME], [LAST_NAME], [EMAIL], [PHONE] FROM [CUSTOMER01]WHERE EMAIL LIKE ‘'”></asp:AccessDataSource>


Leave a comment

Filed under SQL

Comment on this

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s