Page 1 of 1

Writing multiline query using vb.net in ranorex

Posted: Tue Apr 05, 2016 3:31 pm
by vivek.guvva
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"

Re: Writing multiline query using vb.net in ranorex

Posted: Tue Apr 05, 2016 3:57 pm
by krstcs
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

Re: Writing multiline query using vb.net in ranorex

Posted: Tue Apr 05, 2016 4:16 pm
by vivek.guvva
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.

Re: Writing multiline query using vb.net in ranorex

Posted: Tue Apr 05, 2016 4:31 pm
by krstcs
http://stackoverflow.com/questions/1195 ... alent-to-c

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

Re: Writing multiline query using vb.net in ranorex

Posted: Tue Apr 05, 2016 9:17 pm
by vivek.guvva
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

Re: Writing multiline query using vb.net in ranorex

Posted: Thu Apr 07, 2016 3:22 pm
by Diddy
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!