C#.Net Windows Application Hindi编写和显示(C#.Net Windows Application Hindi Writing and display)

编程入门 行业动态 更新时间:2024-10-27 14:27:00
C#.Net Windows Application Hindi编写和显示(C#.Net Windows Application Hindi Writing and display)

我正在使用带有C#的VS 2008 Express处理Windows窗体应用程序项目,其中印地文和英文数据都需要存储在SQL Server 2008 Express数据库中。

我创建了一个包含NVARCAR(MAX)列的表,并使用以下代码将hindi存储到数据库中:

com.CommandText = "INSERT INTO test(name, data) VALUES (@a, @b)"; com.Parameters.Add("@a", SqlDbType.NVarChar).Value = textBox1.Text.Trim(); com.Parameters.Add("@b", SqlDbType.NVarChar).Value = textBox2.Text.Trim(); con.Open(); if (com.ExecuteNonQuery() > 0) MessageBox.Show("Success"); else MessageBox.Show("Failed"); con.Close();

代码工作得很好,并在印地文中保存数据。

以下是我面临的问题:

检索时,我在datagridview和label中看到问号而不是印地文字符。 作为select查询的结果,我需要显示hindi。 这是我正在使用的代码:

com.CommandText = "SELECT data FROM test WHERE name=@name"; com.Parameters.Add("@name", SqlDbType.NVarChar).Value = textBox1.Text.Trim(); con.Open(); SqlDataAdapter da = new SqlDataAdapter(com); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; SqlDataReader dr = com.ExecuteReader(); if(dr.HasRows) { while(dr.Read()) { textBox2.Text = dr.GetValue(0).ToString(); } } con.Close();

注意:印地语比较工作正常,但在数据网格视图和标签/文本框中不显示印地文。

注意:我使用的是可能没有安装hindi的Windows 7。 此外,我无法安装印地文区域语言,因为它需要许可的Windows,我不能确定每台机器都有许可版本。

此外,提到的代码在复制粘贴的印地语上工作正常。 插入数据时我无法输入印地文。

请帮助。

I am working on a windows form application project using VS 2008 Express with C# in which both hindi and english data needs to be stored in SQL Server 2008 Express database.

I have created a table with NVARCAR(MAX) columns and used the following code for storing hindi into database:

com.CommandText = "INSERT INTO test(name, data) VALUES (@a, @b)"; com.Parameters.Add("@a", SqlDbType.NVarChar).Value = textBox1.Text.Trim(); com.Parameters.Add("@b", SqlDbType.NVarChar).Value = textBox2.Text.Trim(); con.Open(); if (com.ExecuteNonQuery() > 0) MessageBox.Show("Success"); else MessageBox.Show("Failed"); con.Close();

The code works perfectly fine, and saves data in hindi.

Now following is the problem I am facing:

When retrieving, I see question marks instead of hindi characters in datagridview and label. I need to show hindi as a result of select query. This is the code that I am using:

com.CommandText = "SELECT data FROM test WHERE name=@name"; com.Parameters.Add("@name", SqlDbType.NVarChar).Value = textBox1.Text.Trim(); con.Open(); SqlDataAdapter da = new SqlDataAdapter(com); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; SqlDataReader dr = com.ExecuteReader(); if(dr.HasRows) { while(dr.Read()) { textBox2.Text = dr.GetValue(0).ToString(); } } con.Close();

NOTE: Hindi comparison works fine but hindi is not displayed in datagridview and label/textbox.

NOTE: I'm using Windows 7 that may not have hindi installed. Also, I cannot install hindi regional language because it demands licensed windows and I cannot be sure that every machine will have a licensed version.

Also, the mentioned code works fine on copy-pasted hindi. I cannot type in hindi while inserting data.

Kindly Help.

最满意答案

虽然安装字体将是唯一的选择,但如果数据以十六进制Unicode存储,则Unicode也可用于显示数据:

void Main() { string input = "0935;093F;0928;094B;0926;"; Regex rx = new Regex(@"([0-9A-Fa-f]{4});"); string output = rx.Replace(input, match => ((char)Int32.Parse(match.Groups[1].Value, NumberStyles.HexNumber)).ToString()); textBox2.Text = output; }

I have found the problem and would like to share the solution so that all visitors may know that this is the right approach and doesnot need much extra labor.

Following are the solutions:

For 1st problem, the code of question is the answer itself. Only the datatypes of both columns: name and data in database needs to be Nvarchar. By mistake, i kept data column as varchar and that was the actual problem.

To allow hindi typing, just add hindi language to the keyboard layout in regional settings and follow the answer of @cshapcoder in this post: Hindi Input in textbox c# application

更多推荐

本文发布于:2023-08-08 01:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466720.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Application   Windows   Net   display   Writing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!