将泰米尔语字符串值在文本框中存储到sql server databse-Windows应用程序

问题描述:

您需要帮助....

我们有一个用asp.net,C#和SQL Server 2005开发的Windows应用程序.

我们使用区域字体(Tamil)在应用程序中显示.数据库中的表设置为nvarchar,以便它接受Unicode字符.

我们在win窗体中有一个文本框,其字体设置为泰米尔语,当我们键入文字时,会在文本框中看到泰米尔语字母,但是如果我们说textbox1.text并保存到数据库,则会另存为英语.

所以我的实际要求是获取文本框值(即泰米尔语字符串)并将该泰米尔语字符串存储到数据库(在db中也应将其存储为泰米尔语). :( :(

如果您不清楚我的问题,请告诉我.....

Hi need help................

We have an windows application developed in asp.net,C# and SQL server 2005.

We use our regional font (Tamil) to display in the application. The table in the database is set to nvarchar, so that it cud accept unicode character.

We have a textbox in the win form where its font set to tamil, when we type we cud see tamil letters in the textbox but if we we say textbox1.text and save to database it saves as english.

So my actual requirement is to get the textbox value (i.e tamil string) and store that tamil string to database (in db also it should stored as tamil). :( :(

please let me know if you are not clear on my question.....

不要那样做-那样会使事情迷惑,然后离开您容易受到SQL注入攻击.

相反,请使用参数化查询-它将泰米尔语与SQL命令隔离开,这意味着它应该可以正常工作:
代替:
Don''t do it that way - it will confuse things, and leave you open to an SQL injection attack.

Instead, use a parametrized query - it isolates the Tamil from the SQL command and means it should just work:
Instead of:
SqlCommand cmd = new SqlCommand("INSERT INTO table VALUES (''" + textboxName.Text + "'')", con);

使用

SqlCommand cmd = new SqlCommand("INSERT INTO table VALUES (@NAME)", con);
cmd.Parameters.AddWithVAlue("@NAME", textboxName.Text);