Question Datagridview Not populating

urielpats

New member
Joined
Jul 29, 2016
Messages
1
Programming Experience
Beginner
Hello, 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

C#:
C#:
[COLOR=#101094]private[/COLOR][COLOR=#101094]void[/COLOR][COLOR=#2B91AF]FillLevyRoll[/COLOR][COLOR=#303336]()[/COLOR][COLOR=#303336]
    [/COLOR][COLOR=#303336]{[/COLOR][COLOR=#303336]
        [/COLOR][COLOR=#101094]try[/COLOR][COLOR=#303336]
        [/COLOR][COLOR=#303336]{[/COLOR][COLOR=#303336]
            [/COLOR][COLOR=#2B91AF]DataTable[/COLOR][COLOR=#303336] dataTableSource [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#101094]new[/COLOR][COLOR=#2B91AF]DataTable[/COLOR][COLOR=#303336]();[/COLOR][COLOR=#303336]


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

            [/COLOR][COLOR=#2B91AF]SqlDataAdapter[/COLOR][COLOR=#303336] adapter [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#101094]new[/COLOR][COLOR=#2B91AF]SqlDataAdapter[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]command[/COLOR][COLOR=#303336]);[/COLOR][COLOR=#303336]
            conn[/COLOR][COLOR=#303336].[/COLOR][COLOR=#2B91AF]Open[/COLOR][COLOR=#303336]();[/COLOR][COLOR=#303336]

            adapter[/COLOR][COLOR=#303336].[/COLOR][COLOR=#2B91AF]Fill[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]dataTableSource[/COLOR][COLOR=#303336]);[/COLOR][COLOR=#303336]
            dgvLevyRoll[/COLOR][COLOR=#303336].[/COLOR][COLOR=#2B91AF]DataSource[/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] dataTableSource[/COLOR][COLOR=#303336];[/COLOR][COLOR=#303336]

        [/COLOR][COLOR=#303336]}[/COLOR][COLOR=#303336]
        [/COLOR][COLOR=#101094]catch[/COLOR][COLOR=#303336]([/COLOR][COLOR=#2B91AF]Exception[/COLOR][COLOR=#303336] ex[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]
        [/COLOR][COLOR=#303336]{[/COLOR][COLOR=#303336]
            [/COLOR][COLOR=#2B91AF]MessageBox[/COLOR][COLOR=#303336].[/COLOR][COLOR=#2B91AF]Show[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"Application Error. err:"[/COLOR][COLOR=#303336]+[/COLOR][COLOR=#303336] ex[/COLOR][COLOR=#303336].[/COLOR][COLOR=#2B91AF]ToString[/COLOR][COLOR=#303336]());[/COLOR][COLOR=#303336]
        [/COLOR][COLOR=#303336]}[/COLOR][COLOR=#303336]
        [/COLOR][COLOR=#101094]finally[/COLOR][COLOR=#303336]
        [/COLOR][COLOR=#303336]{[/COLOR][COLOR=#303336]
            conn[/COLOR][COLOR=#303336].[/COLOR][COLOR=#2B91AF]Close[/COLOR][COLOR=#303336]();[/COLOR][COLOR=#303336]
        [/COLOR][COLOR=#303336]}[/COLOR][COLOR=#303336]

    [/COLOR][COLOR=#303336]}[/COLOR]

 
By the way, opening and closing the connection is pointless because Fill will do that for you, as will Update. You only need to open and close the connection explicitly when using a data adapter if you're performing more than one operation.
 

Latest posts

Back
Top Bottom