我需要能够从组合框或文本框中选择一个员工,并使其适用于我的datagridview,因此我只能看到选定的员工。下面是我的代码,目前用于从表中选择所有内容。有任何想法吗?当你从组合框或文本框中选择时创建一个datagridview
//Report groupbox - load groupbox
private void groupBox7_Enter(object sender, EventArgs e)
{
//Load Username
using (OleDbConnection con = new OleDbConnection(constring))
{
try
{
string query = "SELECT TellerNum FROM Employee ORDER BY TellerNum ASC";
OleDbDataAdapter da = new OleDbDataAdapter(query, con);
con.Open();
DataSet ds = new DataSet();
da.Fill(ds, "Name");
comboBox20.DisplayMember = "TellerNum";
comboBox20.DataSource = ds.Tables["Name"];
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
using (OleDbConnection con = new OleDbConnection(constring))
{
this.sESSIONTableAdapter.Fill(this.trainingDBDataSet5.SESSION);
try
{
con.Open();
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
//Build DataGridView
try
{
sqlAdapter = new OleDbDataAdapter("SELECT SessionName, PrincipleName, SessionDate, TellerNum, Comments, SessionKey FROM [SESSION] WHERE TellerNum = @teller ORDER BY TellerNum;", con);
sqlCommand = new OleDbCommandBuilder(sqlAdapter);
sqlAdapter.InsertCommand = sqlCommand.GetInsertCommand();
sqlAdapter.UpdateCommand = sqlCommand.GetUpdateCommand();
sqlAdapter.DeleteCommand = sqlCommand.GetDeleteCommand();
dataset = new DataSet();
sqlAdapter.Fill(dataset, "[SESSION]");
dataGridView1.DataSource = null;
dataGridView1.DataSource = dataset.Tables["[SESSION]"];
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
DataGridViewLinkCell linkCell = new DataGridViewLinkCell();
dataGridView1[5, i] = linkCell;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
DataGridViewLinkCell linkCell = new DataGridViewLinkCell();
dataGridView1[5, i] = linkCell;
}
}
}
如在搜索和筛选或搜索和选择? – Tom
我编辑了你的标题。请参阅:“[应该在其标题中包含”标签“](http://meta.stackexchange.com/questions/19190/)”,其中的共识是“不,他们不应该”。 –
如果我使用组合框,我会让它从列表中选择一个员工(我已经完成)。然后,您将点击提交,并创建关于该员工信息的datagridview。我可以使用一个文本框,但无论哪种方式,它可能是相同的过程。我只是不知道如何让comboBox或textBox与datagridview关联。 – JoeMarvel