用C#中的mysql表列中的空格替换撇号 [英] Replace apostrophe with a space in mysql table column from C#

查看:94
本文介绍了用C#中的mysql表列中的空格替换撇号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用MySQL表格列中的空格更改每个撇号(')。



错误信息是关于syntaxe echec!



我尝试过:



I want to change every apostrophe( ' )with a space in MySQL table Column .

Error message is about syntaxe echec !

What I have tried:

string query = "update database.table set column = column.Replace('"+"'"+"','"+" "+"');" ;

推荐答案

尝试:

Try :
update database.table set column = REPLACE(column, '\'', ' ')


如果你想逃避MySQL字符串中的单引号,你有两种方法:

1.将它设为两个单引号:

If you want to escape a single quote in a MySQL string, you have two ways of doing it:
1. make it two single quotes:
string query = "update database.table set column = column.Replace('''',' ');" ;



2.使用转义字符( \ ):


2. use the escape character (\):

string query = @"update database.table set column = column.Replace('\'',' ');" ;



在第二个解决方案中,你必须在c#字符串前加上 @ 字符,因此编译器不会将字符串中的转义字符解释为C#转义字符(因此保留原样)。

亲切。


In the second solution you have to prefix your c# string with the @ character, so that the compiler does not interpret the escape character in sthe string as a C# escape character (and thus leaves this as it is).
Kindly.


使用 ALTER TABLE [ ^ ]


这篇关于用C#中的mysql表列中的空格替换撇号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆