Combobox не сортирует на кириллице Visual Studio
уважаемые программисты! Проблема такая:
Не могу понять, так как плохо разбираюсь в программировании и коде. Возникла проблема с сортировкой comboBox. Сначала были проблемы с кириллицей, буквы отображались как "?". Поставил nvarchar в таблицах БД и написал следующий код комбобокса:
private void comboBox_search_SelectionChangeCommitted(object sender, EventArgs e)
{
string selectQuerry = "SELECT * FROM Product WHERE ProdCat=N'"+comboBox_search.SelectedValue.ToString()+"'";
SqlCommand command = new SqlCommand(selectQuerry, dBCon.GetCon());
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataTable table = new DataTable();
adapter.Fill(table);
dataGridView_product.DataSource = table;
}
Проблема в том что сортировка работает только на английском языке: https://ibb.co/pZZ1JPg Так же пример: https://ibb.co/twGv0gM
База данных если что заполнена полностью и создавалась она средствами Visual Studio. Подскажите пожалуйста что можно с этим сделать? Пробовал в строке подключения добавлять разные кодировки, в свойствах что-то прописывал, пробовал много чего уже даже и не вспомню так как проект старый и мне нужно его воскресить. Могу записать видео или скинуть проект полностью, или скинуть нужные строчки кода.
Код формы с проблемой:
using System;
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.SqlClient;
namespace Mini_Market_Management_System
{
public partial class ProductForm : Form
{
DBConnect dBCon = new DBConnect();
public ProductForm()
{
InitializeComponent();
}
private void button_category_Click(object sender, EventArgs e)
{
CategoryForm category = new CategoryForm();
category.Show();
this.Hide();
}
private void ProductForm_Load(object sender, EventArgs e)
{
// TODO: данная строка кода позволяет загрузить данные в таблицу "minimarketdbDataSet.Category". При необходимости она может быть перемещена или удалена.
this.categoryTableAdapter.Fill(this.minimarketdbDataSet.Category);
// TODO: данная строка кода позволяет загрузить данные в таблицу "minimarketdbDataSet.Product". При необходимости она может быть перемещена или удалена.
this.productTableAdapter.Fill(this.minimarketdbDataSet.Product);
getCategory();
getTable();
}
private void getCategory()
{
string selectQuerry = "SELECT * FROM Category";
SqlCommand command = new SqlCommand(selectQuerry, dBCon.GetCon());
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataTable table = new DataTable();
adapter.Fill(table);
comboBox_category.DataSource = table;
comboBox_category.ValueMember = "CatName";
comboBox_search.DataSource = table;
comboBox_search.ValueMember = "CatName";
}
private void getTable()
{
string selectQuerry = "SELECT * FROM Product";
SqlCommand command = new SqlCommand(selectQuerry, dBCon.GetCon());
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataTable table = new DataTable();
adapter.Fill(table);
dataGridView_product.DataSource = table;
}
private void clear()
{
TextBox_id.Clear();
TextBox_name.Clear();
TextBox_price.Clear();
TextBox_qty.Clear();
comboBox_category.SelectedIndex = 0;
}
private void button_add_Click(object sender, EventArgs e)
{
try
{
string insertQuery = "INSERT INTO Product VALUES(" + TextBox_id.Text + ",N'" + TextBox_name.Text + "'," + TextBox_price.Text + "," + TextBox_qty.Text + ",N'" + comboBox_category.Text + "')";
SqlCommand command = new SqlCommand(insertQuery, dBCon.GetCon());
dBCon.OpenCon();
command.ExecuteNonQuery();
MessageBox.Show("Product Added Successfully", "Add Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
dBCon.CloseCon();
getTable();
clear();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button_update_Click(object sender, EventArgs e)
{
try
{
if (TextBox_id.Text == "" || TextBox_name.Text == "" || TextBox_price.Text == "" || TextBox_qty.Text == "")
{
MessageBox.Show("Missing Information", "Missing Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
string updateQuery = "UPDATE Product SET ProdName=N'" + TextBox_name.Text + "',ProdPrice=" + TextBox_price.Text + ",ProdQty=" + TextBox_qty.Text + ",ProdCat=N'" + comboBox_category.Text + "'WHERE ProdId=" + TextBox_id.Text + "";
SqlCommand command = new SqlCommand(updateQuery, dBCon.GetCon());
dBCon.OpenCon();
command.ExecuteNonQuery();
MessageBox.Show("Product Updated Successfully", "Update Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
dBCon.CloseCon();
getTable();
clear();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void dataGridView_product_Click_1(object sender, EventArgs e)
{
TextBox_id.Text = dataGridView_product.SelectedRows[0].Cells[0].Value.ToString();
TextBox_name.Text = dataGridView_product.SelectedRows[0].Cells[1].Value.ToString();
TextBox_price.Text = dataGridView_product.SelectedRows[0].Cells[2].Value.ToString();
TextBox_qty.Text = dataGridView_product.SelectedRows[0].Cells[3].Value.ToString();
comboBox_category.SelectedValue = dataGridView_product.SelectedRows[0].Cells[4].Value.ToString();
}
private void button_delete_Click(object sender, EventArgs e)
{
try
{
if (TextBox_id.Text == "")
{
MessageBox.Show("Missing Information", "Missing Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
string deleteQuery = "DELETE FROM Product WHERE ProdId=" + TextBox_id.Text + "";
SqlCommand command = new SqlCommand(deleteQuery, dBCon.GetCon());
dBCon.OpenCon();
command.ExecuteNonQuery();
MessageBox.Show("Product Deleted Successfully", "Delete Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
dBCon.CloseCon();
getTable();
clear();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button_Refresh_Click(object sender, EventArgs e)
{
getTable();
}
private void comboBox_search_SelectionChangeCommitted(object sender, EventArgs e)
{
string selectQuerry = "SELECT * FROM Product WHERE ProdCat=N'"+comboBox_search.SelectedValue.ToString()+"'";
SqlCommand command = new SqlCommand(selectQuerry, dBCon.GetCon());
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataTable table = new DataTable();
adapter.Fill(table);
dataGridView_product.DataSource = table;
}
private void label_exit_MouseEnter(object sender, EventArgs e)
{
label_exit.ForeColor = Color.Red;
}
private void label_exit_MouseLeave(object sender, EventArgs e)
{
label_exit.ForeColor = Color.Goldenrod;
}
private void label_logout_MouseEnter(object sender, EventArgs e)
{
label_logout.ForeColor = Color.Red;
}
private void label_logout_MouseLeave(object sender, EventArgs e)
{
label_logout.ForeColor = Color.Goldenrod;
}
private void label_logout_Click(object sender, EventArgs e)
{
LoginForm login = new LoginForm();
login.Show();
this.Hide();
}
private void label_exit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button_seller_Click(object sender, EventArgs e)
{
SellerForm seller = new SellerForm();
seller.Show();
this.Hide();
}
private void button_selling_Click(object sender, EventArgs e)
{
SellingForm selling = new SellingForm();
selling.Show();
this.Hide();
}
private void TextBox_id_TextChanged(object sender, EventArgs e)
{
}
private void TextBox_name_TextChanged(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void dataGridView_product_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void comboBox_category_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void comboBox_search_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}