开发者

Bizarre Escape Character Question

I hav开发者_如何转开发e the following c# code embedded in a literal <% %> of a c# asp.net page

string commandString = "SELECT tblData.Content " +
                        "FROM tblData " +
                        "WHERE (tblData.ref = N\'%"+myCurrentREF+"%\')";

This is breaking my code since it apparently cannot use the \' escape character. Why is it so? other escape characters like \" are working so why isn't \' working?


The sequence \" is "working" if you choose " as string terminator.

If you'd use @" as initial string terminator, the sequence \" does not escape the quote (but "" does).

So \" is not a "universal" escape sequence, and \' is none.


You shouldn't need to escape the single quote. but if you do, you can always try the @ approach.


string commandString = "SELECT tblData.Content " +
                    "FROM tblData " +
                    "WHERE (tblData.ref = '%"+myCurrentREF+"%')";

This is the correct way, but instead of = did not mean like?, or you string always start with %?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜