Solved

How do I carry on a line?

Posted on 2006-10-23
13
205 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now