How to include char & in a string in VB.NET?

G

Guest

I do not how to include char & in a string. In C, use \&. But I do not know
how in VB.NET? any one give me hand?

I have the following error message.

David

......
Syntax error: Missing operand after ''&''prot='' operator.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.Data.SyntaxErrorException: Syntax error: Missing
operand after ''&''prot='' operator.

Source Error:


Line 85:
Line 86:
'dsResource.Tables("Resource4Spec").Columns.Add("URLQuery",
Type.GetType("System.String"), "MethodName +" & "'?pkey='" & "+ PatientKey")
Line 87:
dsResource.Tables("Resource4Spec").Columns.Add("URLQuery",
Type.GetType("System.String"), "MethodName +" & "'?pkey='" & "+ PatientKey" &
"'&'" & "'prot='" & "+ Protocol")
Line 88:
Line 89: 'binding datagrid
 
K

Kevin Spencer

How about something like the following?

Dim s As String = "123&abc"

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
 
K

Karl Seguin

I think you just got mixed up with your single quotes (you have '&''prot= ,
notice the double single quotes).

I _think_ this is what you want:
"MethodName +" & "'?pkey='" & "+ PatientKey" & " + '&prot='" & "+ Protocol"

I also don't understand why you are breaking up ur string..wouldn't:
"MethodName + '?pkey=' + PatientKey + '&prot='+ Protocol"

work just as well and be a way easier to read?

Karl
 
G

Guest

I do not how to include char & in a string. In C, use \&. But I do
not know how in VB.NET? any one give me hand?

Take a look a the chr function.

You pass a ASCII code into the chr function.

i.e. chr(34), etc.
 
G

Guest

Thank you all.

I will try it tomorrow in workplace.
MethodName, PatientKey, Protocol are column names.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top