i have a method private void FillLevyRoll(), i put the method in a button on click event to fill a datagridview dgvLevyRoll my problem is when i run i am not getting an error and the dgv is remaining empty.Im lost confused tried but to no avail.
The query works in SQL management studio
- 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();
- }
-
- }