View Single Post
  #2 (permalink)  
Old December 16th, 2011, 02:27 PM
Rod Stephens's Avatar
Rod Stephens Rod Stephens is offline
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Code:
"Data Source= """ & txtDatabase.Text & """; " & _
"Persist Security Info= False"
That looks confusing but it's not a typo.

Visual Basic uses double quotes to delimit strings. So what if you want to put a double quote inside a string? If you tried "apple " banana" it would think the middle quote closed the string and wouldn't know what to do with banana".

To tell Visual Basic to include a quote within a string, you double it, so in this example would use "apple "" banana".

When the double quote comes at the beginning or end of a string, you get three in a row, which looks particularly odd.

So here's what the original code looks like if I replace the quotes inside the string with an X so it's easier to see:

Code:
"Data Source= X" & txtDatabase.Text & "X; " & _
"Persist Security Info= False"
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)