C#Two Form,两个Datagridview,具有相同的数据源

时间:2018-05-02 20:06:31

标签: c# mysql winforms datagridview

我对我的代码感到困惑。我不知道是什么问题。我在互联网上搜索这个,答案说我需要过滤DataGridView并显示数据库中的确切值。但是,如果我放置代码并从DataSet,DataAdapter更改,则无效。如何过滤值?

这是我的代码。

表单1,代码1,DataGridView 1。

 public void DataView()
    {
        Connection.Open();
        MySqlCommand Command = new MySqlCommand("Select * From clientaccountcreditdebitdb", Connection);
        DataTable dt = new DataTable();
        MySqlDataAdapter da = new MySqlDataAdapter(Command);
        da.Fill(dt);
        dgvCreditList.DataSource = null;
        dgvCreditList.AllowUserToAddRows = false;
        dgvCreditList.AutoGenerateColumns = false;
        dgvCreditList.ColumnCount = 9;
        dgvCreditList.Columns[0].HeaderText = "id";
        dgvCreditList.Columns[0].DataPropertyName = "ID";
        dgvCreditList.Columns[1].HeaderText = "Account Name";
        dgvCreditList.Columns[1].DataPropertyName = "CreditAccountName";
        dgvCreditList.Columns[2].HeaderText = "Account Number";
        dgvCreditList.Columns[2].DataPropertyName = "CreditAccountNumber";
        dgvCreditList.Columns[3].HeaderText = "Description";
        dgvCreditList.Columns[3].DataPropertyName = "CreditDescription";
        dgvCreditList.Columns[4].HeaderText = "References / Cheque No";
        dgvCreditList.Columns[4].DataPropertyName = "CreditReferencesCheque";
        dgvCreditList.Columns[5].HeaderText = "Bank Name";
        dgvCreditList.Columns[5].DataPropertyName = "CreditBankName";
        dgvCreditList.Columns[6].HeaderText = "Date";
        dgvCreditList.Columns[6].DataPropertyName = "CreditDate";
        dgvCreditList.Columns[7].HeaderText = "Transaction Type";
        dgvCreditList.Columns[7].DataPropertyName = "CreditTransactionType";
        dgvCreditList.Columns[8].HeaderText = "Amount";
        dgvCreditList.Columns[8].DataPropertyName = "CreditAmount";
        dgvCreditList.Columns[0].Visible = false;
        Connection.Close();
    }

表格2,代码2,DataGrid 2。

public void DataView()
    {
        Connection.Open();
        MySqlCommand Command = new MySqlCommand("Select * From clientaccountcreditdebitdb", Connection);
        DataTable dtdebit = new DataTable();
        MySqlDataAdapter da = new MySqlDataAdapter(Command);
        da.Fill(dtdebit);
        dgvDebitList.DataSource = null;
        dgvDebitList.AllowUserToAddRows = false;
        dgvDebitList.AutoGenerateColumns = false;
        dgvDebitList.ColumnCount = 9;
        dgvDebitList.Columns[0].HeaderText = "id";
        dgvDebitList.Columns[0].DataPropertyName = "ID";
        dgvDebitList.Columns[1].HeaderText = "Account Name";
        dgvDebitList.Columns[1].DataPropertyName = "DebitAccountName";
        dgvDebitList.Columns[2].HeaderText = "Account Number";
        dgvDebitList.Columns[2].DataPropertyName = "DebitAccountNumber";
        dgvDebitList.Columns[3].HeaderText = "Description";
        dgvDebitList.Columns[3].DataPropertyName = "DebitDescription";
        dgvDebitList.Columns[4].HeaderText = "References / Cheque No";
        dgvDebitList.Columns[4].DataPropertyName = "DebitReferencesCheque";
        dgvDebitList.Columns[5].HeaderText = "Bank Name";
        dgvDebitList.Columns[5].DataPropertyName = "DebitBankName";
        dgvDebitList.Columns[6].HeaderText = "Date";
        dgvDebitList.Columns[6].DataPropertyName = "DebitDate";
        dgvDebitList.Columns[7].HeaderText = "Transaction Type";
        dgvDebitList.Columns[7].DataPropertyName = "DebitTransactionType";
        dgvDebitList.Columns[8].HeaderText = "Amount";
        dgvDebitList.Columns[8].DataPropertyName = "DebitAmount";
        dgvDebitList.Columns[0].Visible = false;
        dgvDebitList.DataSource = dtdebit;
        Connection.Close();
    }

And here my form.

这里有什么问题吗?

0 个答案:

没有答案