p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Visual Basic 2008 Programmer's Reference ISBN: 978-0-470-18262-8 (http://p2p.wrox.com/forumdisplay.php?f=384)
-   -   Typo, Chapter 20 page 416 (http://p2p.wrox.com/showthread.php?t=86048)

eightbits2011 December 15th, 2011 07:35 PM

Typo, Chapter 20 page 416
 
In the code example "make the connect string" the following line is
shown as:
"Data Source= """ & txtDatabase.Text & """; " & _ [:confused:]
"Persist Security Info= False"

Is this a typo? What is confusing is the incidence of """ in the line of code. The three (""") looks confusing. If it is a typo can anyone post
the correct text?

Thanks very much.
Cheers

Rod Stephens December 16th, 2011 02:27 PM

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"


eightbits2011 December 16th, 2011 07:07 PM

OK, thanks for the very quick response.
The three double quotes just look like something isn't right.
I will give string to a textbox just to make sure I understand my
lack of understanding.[:I]

So, the string itself is passing a quote ?

I think my problem is not being up to snuff using SQL.[B)]

Once again, thanks for the reply.

Cheers

Rod Stephens December 16th, 2011 07:15 PM

Quote:

So, the string itself is passing a quote ?
Yup. Two of them actually. It is confusing until you've seen it a bunch.


All times are GMT -4. The time now is 05:28 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.