Solved

How do I carry on a line?

Posted on 2006-10-23
13
239 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 66

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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

691 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