创建一个记录并在C#的组合框中更新它 [英] Create a record and update that in a combo box in C#
问题描述
我正在创建员工并与员工指定联系。
员工数据存储在一个文件中,如名称和其他详细信息。存储在其他文件中的设计。当我在那里创建员工姓名的时候,我正在显示一个带有指定表的一个组合框。虽然我正在创建员工名称并不是我需要的组合框,我创建了一个按钮来创建指定。当我点击那个按钮时,我正在调用指定创建表单。我正在进入新的名称。但是这个指定并没有在组合框中更新我在员工创建表单中的内容。那么怎么做。
我尝试过:
我不知道如何刷新该组合框。我每次加载表单时都会刷新组合框。
I am Creating employee and going to connect with employees designation.
Employees data stored in one file like name and other details.Designation stored in other. when I am creating employee name there i am displaying one combo box bounded with designation table.While I am creating employees designation is not there what I need in combo box, I created one button to create designation. When I click on that button I am calling designation create form. There I am Entering new designation. But that designation is not updating in combo box what I placed in employee creation form. So how to do that.
What I have tried:
I am not getting any idea how to refresh that combo box. I am refreshing that combobox every time when I am Loading the form.
推荐答案
使用 DataGridView 可能更简单,例如:
Maybe it's simpler to use a DataGridView, example:
using System;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Windows.Forms;
// Put below lines in a method
string customers = "SELECT * FROM Customers";
using (SqlConnection con = new SqlConnection("Data Source=MY-PCNAME;Initial Catalog=northwind;Integrated Security=True"))
{
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(customers, con);
da.Fill(ds, "Customers");
dataGridView.AutoGenerateColumns = true;
dataGridView.DataSource = ds;
dataGridView.DataMember = "Customers";
}
这篇关于创建一个记录并在C#的组合框中更新它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!