Solved

How do I carry on a line?

Posted on 2006-10-23
13
234 Views
Last Modified: 2010-04-23
Hi,

I have a long mysql query and woould like to break it up into lines.

How do I carry on a line in VB.  I have seen underscores being used "_"?

Please help?
0
Comment
Question by:nickmarshall
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +3
13 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17788130
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 17788135
{my personal preference, others may vary}

Dim sSQL as String

sSQL = "SELECT blah1, blah2, blah3 "
sSQL = sSQL & "FROM blahA "
sSQL = sSQL & "INNER JOIN blahB ON blahA.ID = blahB.ID "
sSQL = sSQL & "WHERE blah42='banana'"

0
 
LVL 10

Expert Comment

by:Kinger247
ID: 17788174
or

        Dim SQL As New System.Text.StringBuilder

        SQL.Append("SELECT blah1, blah2, blah3 ")
        SQL.Append("FROM blahA ")
        SQL.Append("INNER JOIN blahB ON blahA.ID = blahB.ID ")
        SQL.Append("WHERE blah42='banana'")

        Console.Write(SQL.ToString)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:GivenRandy
ID: 17788193
I also do jimhorn's style, but in .NET it can be less typing if you use the "&=" instead (note that the string is initially assigned to String.Empty):

Dim sSQL as String = String.Empty

sSQL &= "SELECT blah1, blah2, blah3 "
sSQL &= "FROM blahA "
sSQL &= "INNER JOIN blahB ON blahA.ID = blahB.ID "
sSQL &= "WHERE blah42='banana'"
0
 
LVL 1

Author Comment

by:nickmarshall
ID: 17788317
Thanks experts, does this look right?....

        Dim SQL As String = String.Empty

        SQL &= " Insert Into Hardware (ID, CSName, CpuCurrenClockSpeed, CpuStatus,"
        SQL &= " CpuManufacturer, CpuName, CpuSocketDesignation, SystemName, "
        SQL &= " SystemOrganization, SystemRegisteredUser, SystemSerialNumber, "
        SQL &= " SystemTotalVisibleMemorySize, SystemWindowsDirectory, SoundManufacturer, "
        SQL &= +" SoundProductName, MotherboardManufacturer, MotherboardProduct)"
0
 
LVL 9

Expert Comment

by:GivenRandy
ID: 17788349
Looks okay except for the extra "+" in the last line.  Are you going to add the "VALUES" part, too?
0
 
LVL 1

Author Comment

by:nickmarshall
ID: 17788567
I have outputted the following query to the console;

        SQL &= "Insert Into Hardware (ID, CSName, CpuCurrenClockSpeed, CpuStatus, "
        SQL &= "CpuManufacturer, CpuName, CpuSocketDesignation, SystemName, "
        SQL &= "SystemOrganization, SystemRegisteredUser, SystemSerialNumber, "
        SQL &= "SystemTotalVisibleMemorySize, SystemWindowsDirectory, SoundManufacturer, "
        SQL &= "SoundProductName, MotherboardManufacturer, MotherboardProduct)"
        SQL &= "VALUES ("
        SQL &= "' ', '" & CSNameNode.InnerText & "', '" & CpuCurrentClockSpeed.InnerText & "', "
        SQL &= "' ', '" & CpuManufacturer.InnerText & "', '" & CpuName.InnerText & "', "
        SQL &= "' ', '" & CpuSocketDesignation.InnerText & "', '" & CpuStatus.InnerText & "', "
        SQL &= "' ', '" & SystemName.InnerText & "', '" & SystemOrganization.InnerText & "', "
        SQL &= "' ', '" & SystemRegUser.InnerText & "', '" & SystemSerialNumber.InnerText & "', "
        SQL &= "' ', '" & SystemTotVisMem.InnerText & "', '" & SystemWindows.InnerText & "', "
        SQL &= "' ', '" & SoundManufacturer.InnerText & "', '" & SoundProductName.InnerText & "', "
        SQL &= "' ', '" & MotherboardManufacturer.InnerText & "', '" & MotherboardProduct.InnerText & "', "
        SQL &= "' ', '" & DisplayDriver.InnerText & "', '" & DisplayName.InnerText & "' )"


The parts after the "VALUES", with the variables produce alot of errors, I get invalid formatting such as;

'F:\WINDOWS', ' ', 'Intel',

Where there are two  ' '

..and it should read 'F:\WINDOWS', 'Intel',
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
ID: 17788616
       SQL &= "Insert Into Hardware (ID, CSName, CpuCurrenClockSpeed, CpuStatus, "
        SQL &= "CpuManufacturer, CpuName, CpuSocketDesignation, SystemName, "
        SQL &= "SystemOrganization, SystemRegisteredUser, SystemSerialNumber, "
        SQL &= "SystemTotalVisibleMemorySize, SystemWindowsDirectory, SoundManufacturer, "
        SQL &= "SoundProductName, MotherboardManufacturer, MotherboardProduct)"
        SQL &= "VALUES "
        SQL &= "( '" & CSNameNode.InnerText & "', '" & CpuCurrentClockSpeed.InnerText & "' "
        SQL &= ", '" & CpuManufacturer.InnerText & "', '" & CpuName.InnerText & "' "
        SQL &= ", '" & CpuSocketDesignation.InnerText & "', '" & CpuStatus.InnerText & "' "
        SQL &= ", '" & SystemName.InnerText & "', '" & SystemOrganization.InnerText & "' "
        SQL &= ", '" & SystemRegUser.InnerText & "', '" & SystemSerialNumber.InnerText & "' "
        SQL &= ", '" & SystemTotVisMem.InnerText & "', '" & SystemWindows.InnerText & "' "
        SQL &= ", '" & SoundManufacturer.InnerText & "', '" & SoundProductName.InnerText & "' "
        SQL &= ", '" & MotherboardManufacturer.InnerText & "', '" & MotherboardProduct.InnerText & "' "
        SQL &= ", '" & DisplayDriver.InnerText & "', '" & DisplayName.InnerText & "' )"
0
 
LVL 1

Author Comment

by:nickmarshall
ID: 17788657
Right got that working now however in some cases the variables produce an output as follows;

 'Gigabyte Motherboard', '          Windows XP Professional',

Therefore Windows XP Professional has many spaces, would this effect the query, or would mysql simply ignore the lines?
0
 
LVL 1

Author Comment

by:nickmarshall
ID: 17788720
This is causing sytax error when I try to execute the query.
0
 
LVL 1

Author Comment

by:nickmarshall
ID: 17788774
Here is what the string looks like;

Insert Into Hardware (ID, CSName, CpuCurrenClockSpeed, CpuStatus, CpuManufacturer, CpuName, CpuSocketDesignation, SystemName, SystemOrganization, SystemRegisteredUser, SystemSerialNumber, SystemTotalVisibleMemorySize, SystemWindowsDirectory, SoundManufacturer, SoundProductName, MotherboardManufacturer, MotherboardProduct) VALUES ('SUPPORT-PC ', '1716', 'GenuineIntel ', '                Intel(R) Celeron(R) CPU 1.70GHz', 'Socket 478 ', 'OK', 'Microsoft Windows XP Professional|F:\WINDOWS|\Device\Harddisk0\Partition2 ', 'Our company', 'The Hostmaster ', '55274-OEM-0014286-12345', '1048052 ', 'F:\WINDOWS', 'Intel ', 'Intel(r) 82801BA/BAM AC'97 Audio Controller', 'Gigabyte Technology Co., Ltd. ', '8ID533  ', '6.13.10.4109 ', 'NVIDIA Quadro4 NVS' )

As you can see there are gaps in the above, also there is a comma within a string.  Please help
0
 
LVL 7

Expert Comment

by:Mohamed Zedan
ID: 17792190
you should type the variables like this samplevar.innertext.trim
0
 
LVL 9

Expert Comment

by:GivenRandy
ID: 17792305
What is the exact error that you are getting? It looks like you have 17 items in the first section and 18 in the VALUES part.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question