2016-03-29 18 views
0

SQLデータベースを使用してテキストボックスにアラビア文字の表示に問題があります。私はnvarcharタイプをSQLに使用し、アイテムコンボボックスのラテン文字を完全に(img1)選択すると、コンボボックスでアラビア語アイテムを選択しようとすると、テキストボックス1と2(img2)では何も起こりません。コンボボックス(アラビア文字)を選択した場合のテキストボックスのデータベース値

コード:クエリでのアラビア文字列の前に 'N' を追加

using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using System.Data.Sql; 
using System.Data.SqlClient; 

namespace testconnection 
{ 
    public partial class Form1 : Form 
    { 
     private SqlConnection con; 
     private SqlCommand cmd; 
     private SqlDataAdapter da; 
     private DataTable dt; 
     private SqlDataReader dr; 
     public Form1() 
     { 
      InitializeComponent(); 
      combo(); 

     } 

     void combo() 
     { 
      con = new SqlConnection(
       @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\vemmi\Documents\user.mdf;Integrated Security=True"); 
      con.Open(); 
      cmd = new SqlCommand("SELECT usrs FROM usrtest", con); 
      try 
      { 
       SqlDataReader dr = cmd.ExecuteReader(); 

       while (dr.Read()) 
       { 
        comboBox1.Items.Add(dr["usrs"]); 

       } 

       dr.Close(); 

      } 
      catch (Exception ex) 
      { 
       MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); 
      } 
     } 

     private void button2_Click(object sender, EventArgs e) 
     { 
      Form2 c = new Form2(); 
      c.ShowDialog(); 
     } 

     private void Form1_Load(object sender, EventArgs e) 
     { 

     } 


     private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) 
     { 

      con = new SqlConnection(
       @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\vemmi\Documents\user.mdf;Integrated Security=True"); 
      con.Open(); 

      cmd = new SqlCommand("SELECT * FROM usrtest WHERE usrs like '" + comboBox1.Text + "' "); 

      cmd.Connection = con; 

      try 
      { 
       SqlDataReader dr = cmd.ExecuteReader(); 


       while (dr.Read()) 
       { 

         string p = dr["pwd"].ToString(); 
         string n = dr["nbr"].ToString(); 


         textBox2.Text = p; 
         textBox3.Text = n; 

       } 

      } 
      catch (Exception ex) 
      { 
       MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); 
      } 


     } 

enter image description here

答えて

0

してみてください。

cmd = new SqlCommand("SELECT * FROM usrtest WHERE usrs like N'" + comboBox1.Text + "' "); 
関連する問題