更新unicode查询 [英] update unicode Query

查看:175
本文介绍了更新unicode查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更新表中的unicode数据.
我使用以下查询来插入unicode ...

字符串查询="INSERT AddDoze值(N""+ txt_doze.Text +"'');
多数民众赞成在正常工作...

但是我在更新数据时面临问题.我使用以下查询来更新unicode


I want to UPdate unicode Data in my table.
i used following Query for insert unicode ...

string query = "INSERT AddDoze values (N'' " + txt_doze.Text + "'')";
and thats work properly ...

But i am facing problem in updating Data. I used following Query for updating unicode


string Query = "update dbo.AddDoze set Meddoze= ''" + DozeName + "'' where ID= ''" + ID + "'' ";

..

当我更新数据时...像问号一样存储在数据库表中???????

因此,请任何人告诉我,有什么解决方案(查询)可以更新C#.net中的Unicode数据吗?

..

when i m updating data ... its stored in Database table like a Question marks ???????

So please any one tell me there is any solution(Query) to updating Unicode Data in C# .net?

推荐答案

首先,不要连接字符串以构建SQL命令.它使您对意外或蓄意的SQL注入攻击敞开大门,这可能会破坏整个数据库.请改用参数化查询.

您可能会发现它可以改善情况,但是如果不能这样做,则可能需要将数据从Unicode转换为ASCII-尽管在原始代码中以"N"作为前缀的SQL非常完美地支持Unicode.
因此,将前缀添加到第二个代码示例中,它也将在那里工作!
First off, do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.

You may find that improves things, but if it doesn''t then you may need to convert the data from Unicode to ASCII instead - although SQL supports Unicode perfectly happily when prefixed by ''N'' as in your original code.
So add the prefix to your second code example, and it should work there as well!


如果ID为Interger类型,则不要在ID中使用".在下面的SQL-
中使用
If ID is Interger type then dont use '' with ID. Use Below SQL-

string Query = "update dbo.AddDoze set Meddoze = ''" + DozeName + "'' where ID = " + ID +"";


这篇关于更新unicode查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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