开发者

how to insert this text in mysql

i want to insert some text in mysql but text have double quote "" in middle of the text then insert query fai开发者_运维技巧led what i do in c# to solve this issue

Incorrect string value: '\xE0\xA4\x85\xE0\xA4\xAD...' for column 'colname' at row 1

ex: this is a simple "text"


You can use query parameters. For example:

sql.command.Parameters.AddWithValue("?UserName", username);
sql.command.Parameters.AddWithValue("?Password", password);
sql.command.CommandText = "SELECT * FROM `users` WHERE `username`=?UserName
  AND `password`=?Password LIMIT 1"; 


use the escape character ('\') to escape the quotes so they can be interpreted literally.


Use a \ char to escape the quotes. So instead of " you will have \". For a longer, more realistic example, you might have something like:

"This string has quotes around \"this phrase\" but they are part of the value"

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜