Answered Concatenate Query String

AussieBoy

Well-known member
Joined
Sep 7, 2020
Messages
78
Programming Experience
Beginner
Hi,
I have the below code.
How can I concatenate the number of the "Group 1" into the query string, so that I can increment it.
I have tried a number of ways with no success.
I am sure I have done it before a while back. But cannot find an example.
Thanks,
C#:
retobj = MySoap.ExecuteQuery("Select CurrentValueFormatted, FullName from SPoint where FullName='XXXX.Group 1.XXXX.reference'", obj, out limit);
Thanks,
 
Last edited by a moderator:
It's just a string. How do you usually concatenate strings?
C#:
"blah " + someVariable + " blah"
or, in the days of string interpolation:
C#:
$"blah {someVariable} blah"
 
Hi,
Yes, I had tried the " + variable + ". Thanks for confirming.

The problem I discovered was, I had tried to use the "i" form a for loop as the variable.
When I moved "i" into a variable and used that variable it worked.
So my bad. Glad to have found it though.

Code:
for (int i = 1; i < 2; i++)
                    {

                        int mNo = i
;
 
The loop counter is a variable so you can use it just like any other variable. This:
C#:
for (var i = 1; i <= count; i++)
{
    retobj = MySoap.ExecuteQuery("Select CurrentValueFormatted, FullName from SPoint where FullName='XXXX.Group " + i + ".XXXX.reference'", obj, out limit);
    
    // Use retobj here.
}
should work without issue.
 
Back
Top Bottom