C#cant填充datagridview

时间:2016-07-28 10:30:54

标签: c# sql datagridview

我遇到了类似的问题,我看到了如何修复它,试图在相同的帖子上发帖但是它有限。

我有一个方法private void FillLevyRoll(),我把方法放在click事件的按钮上来填充datagridview dgvLevyRoll我的问题是当我运行时我没有收到错误而dgv仍然是空的。我迷失了尝试但无济于事。

该查询适用于SQL管理工作室

 private void FillLevyRoll()
    {
        try
        {
            DataTable dataTableSource = new DataTable();


            SqlCommand command = new SqlCommand("SELECT  Refrence" +
                ", MAX(CASE WHEN AccNumber = '1010000' THEN amount END) AS Opening" +
                ", MAX(CASE WHEN AccNumber = '1010000' THEN amount END) AS electricity" +
                ", MAX(CASE WHEN AccNumber = '1045000' THEN amount END) AS water" +
                ", MAX(CASE WHEN AccNumber = '1000000' THEN amount END) AS levy" +
                ", MAX(CASE WHEN AccNumber = '2750000' THEN amount END) AS Interest" +
                ", MAX(CASE WHEN AccNumber = '4000000' THEN amount END) AS Legal" +
                ", MAX(CASE WHEN AccNumber = '4350003' THEN amount END) AS Other" +
                ", MAX(CASE WHEN AccNumber = '8400000' THEN amount END) AS Payments" +
                ", MAX(CASE WHEN AccNumber = '1000000' THEN amount END) AS Due" +
                " FROM dbo.vw_LedgerTransactions" +
                " GROUP BY Refrence ", conn);

            SqlDataAdapter adapter = new SqlDataAdapter(command);
            conn.Open();

            adapter.Fill(dataTableSource);
            dgvLevyRoll.DataSource = dataTableSource;

        }
        catch (Exception ex)
        {
            MessageBox.Show("Application Error. err:" + ex.ToString());
        }
        finally
        {
            conn.Close();
        }

    }

0 个答案:

没有答案