Writing multiline query using vb.net in ranorex

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
vivek.guvva
Posts: 31
Joined: Mon Feb 22, 2016 7:21 pm

Writing multiline query using vb.net in ranorex

Post by vivek.guvva » Tue Apr 05, 2016 3:31 pm

Hi,
I have to write a very big sql query to retreive data from hadoop database. It is showing syntax error when the query is included in double quotes. Please let me know the easy way to write mutliline sql query in vb.net. Below is the query that i have used and it is not working. I have to pass the year parameter to query as well.

Dim year as Int32 = 2016
Dim getDateID As String = "select col1,
col2,
col9,
round(sum(col3)) as ATD
from datbase.table
where col4=&year and col5=1"

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Writing multiline query using vb.net in ranorex

Post by krstcs » Tue Apr 05, 2016 3:57 pm

VB uses end-of-line characters ("\r\n") as statement breaks (C# uses ";") so you can't have line breaks in your quote statements. You will need to put the whole string statement on the same line. There are ways around it but they are harder to read than just having a long string.

For instance, you could do this:

Code: Select all

Dim query AS String = "select * "
query = query + "from myTable"

NOTE: This was changed in the latest release of .NET (4.6), but Ranorex defaults to .NET 3.5, so unless you install 4.6, you are out of luck.

Yet another reason not to use VB... :D
Shortcuts usually aren't...

vivek.guvva
Posts: 31
Joined: Mon Feb 22, 2016 7:21 pm

Re: Writing multiline query using vb.net in ranorex

Post by vivek.guvva » Tue Apr 05, 2016 4:16 pm

Thanks for your reply. I am using ranorex version 5.4.5....With the same version, we are able to write multiline sql queries by using @ in front of the query.
Ex:
String getDateID = @"select col1,
col2,
col9,
round(sum(col3)) as ATD
from datbase.table
where col4=&year and col5=1"

Please let me know if there is any possibility like this in VB.net as well.

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Writing multiline query using vb.net in ranorex

Post by krstcs » Tue Apr 05, 2016 4:31 pm

http://stackoverflow.com/questions/1195 ... alent-to-c

This is another way, but no, there is no equivalent to '@"string"' in VB.
Shortcuts usually aren't...

vivek.guvva
Posts: 31
Joined: Mon Feb 22, 2016 7:21 pm

Re: Writing multiline query using vb.net in ranorex

Post by vivek.guvva » Tue Apr 05, 2016 9:17 pm

Hi, Instead of writing the query in the code, Can we store the queries in excel and pass the query as parameter using an excel data connector.
If this is possible, Can we include parameters in that query which we are storing in excel sheet.

Thanks
Vivek

Diddy
Posts: 7
Joined: Tue Feb 09, 2016 4:00 pm

Re: Writing multiline query using vb.net in ranorex

Post by Diddy » Thu Apr 07, 2016 3:22 pm

krstcs wrote:[...]there is no equivalent to '@"string"' in VB.
Agreed!
At least you don't have to terminate the multiline strings with _

As you think of using parameters from an connector it could be useful to structure your statement using Linq anyway -> as described in some of krstcs' linked stackoverflow posts...

Have fun!