Issue with double quotes

  • Thread starter Thread starter SK
  • Start date Start date
S

SK

Hello all,
I need to pass a string to a sql procedure in this fashion
<DateParam>
<BeginDate="2007-01-25" BeginTime="08:30 AM" EndTime="09:45AM"/>
</DateParam>

If you notice the date and time are enclosed in double quotes. How do
I achieve this in C#
I tried using the escape sequence "\"", but the \ also gets included
and the stored procedure fails.

The stored procedure is not ours and is being called from our code to
update another db.

Any help would be appreciated
SS
 
SK said:
Hello all,
I need to pass a string to a sql procedure in this fashion
<DateParam>
<BeginDate="2007-01-25" BeginTime="08:30 AM" EndTime="09:45AM"/>
</DateParam>

If you notice the date and time are enclosed in double quotes. How do
I achieve this in C#
I tried using the escape sequence "\"", but the \ also gets included
and the stored procedure fails.

How are you specifying the text? If it's within the C# code, you need
the \ and it *won't* be in the "real" string. If it's within a file,
you *don't* need the \ as the C# compiler won't be processing it.
 
Another question to ask is whether or not you are using parameterized
queries to send the parameters to the stored procedure on the server, or
whether you are creating the exec statement yourself (complete with
parameters).

If you are not using the parameters collection that a command exposes
and then assigning your string to that, I would guess that most likely, you
are generating the string correctly (as a parameter) but you are not
translating it correctly when sending it to the stored procedure.

You should let the data provider model do that for you (if you are not
already).
 
How are you specifying the text? If it's within the C# code, you need
the \ and it *won't* be in the "real" string. If it's within a file,
you *don't* need the \ as the C# compiler won't be processing it.

The string is within C# code and not within a file. I tried using
"\"". The string that gets passed to sql looks like this
<DateParam>
<BeginDate=\"2007-05-30\" BeginTime=\"8:00 AM\" EndTime=\"9:00 AM\"/>
</DateParam>
 
Another question to ask is whether or not you are using parameterized
queries to send the parameters to the stored procedure on the server, or
whether you are creating the exec statement yourself (complete with
parameters).

If you are not using the parameters collection that a command exposes
and then assigning your string to that, I would guess that most likely, you
are generating the string correctly (as a parameter) but you are not
translating it correctly when sending it to the stored procedure.

You should let the data provider model do that for you (if you are not
already).

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)



How are you specifying the text? If it's within the C# code, you need
the \ and it *won't* be in the "real" string. If it's within a file,
you *don't* need the \ as the C# compiler won't be processing it.

- Show quoted text -

I am using parameterized queries.
 
SK said:
The string is within C# code and not within a file. I tried using
"\"". The string that gets passed to sql looks like this
<DateParam>
<BeginDate=\"2007-05-30\" BeginTime=\"8:00 AM\" EndTime=\"9:00 AM\"/>
</DateParam>

My guess is that you're viewing that in the debugger - if so, the
slashes really aren't there.

Try printing it to a message box or to the console and you'll see the
real string.

See http://pobox.com/~skeet/csharp/strings.html#debugger for more on
this.
 
My guess is that you're viewing that in the debugger - if so, the
slashes really aren't there.

Try printing it to a message box or to the console and you'll see the
real string.

Seehttp://pobox.com/~skeet/csharp/strings.html#debuggerfor more on
this.

You are right Jon. I am viewing that in the debugger. But will it be
without the the slashes when the procedure is being executed?
Thanks for your responses
S
 
SK said:
You are right Jon. I am viewing that in the debugger. But will it be
without the the slashes when the procedure is being executed?
Thanks for your responses
S

Yes.
 
SK said:
You are right Jon. I am viewing that in the debugger. But will it be
without the the slashes when the procedure is being executed?
Thanks for your responses

As I said before, it doesn't have the slashes in at all - it's just the
debugger trying to be smart (and failing - it confuses lots of people).
 

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

Back
Top