Solved

How do I carry on a line?

Posted on 2006-10-23
13
221 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
  • 5
  • 3
  • 2
  • +3
13 Comments
 
LVL 142

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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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 142

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 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