Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi guys

I have a datagridview where the third column is a custom column with all days
of a month. It takes data with a query who distinct the column Improve.
Here is the code :
VB
Private Sub fill_impro()
        dgImprove.Rows.Clear()
        Try
            Dim i As Integer = 0
            Dim query As String = "SELECT Improve,Price,Active,Idate FROM (SELECT Improve,Price,Active,Idate, ROW_NUMBER() OVER (PARTITION BY Price ORDER BY Price) AS rn  FROM tblImprove) tmp WHERE rn = 1"
            cmd = New SqlCommand(query, clsMSSQL.con)
            myDR = cmd.ExecuteReader
            If myDR.HasRows Then
                While myDR.Read
                    dgImprove.Rows.Add()
                    dgImprove.Rows(i).Cells(0).Value = myDR.GetDecimal(myDR.GetOrdinal("Price"))
                    dgImprove.Rows(i).Cells(1).Value = myDR.GetString(myDR.GetOrdinal("Improve"))
                    Dim myday As Integer = DatePart(DateInterval.Day, myDR.GetValue(myDR.GetOrdinal("Idate")))
                    dgImprove.Rows(i).Cells(myday + 1).Value = myDR.GetInt32(myDR.GetOrdinal("Active"))
                    i = i + 1
                            End While
                        End If
            myDR.Close()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Σφάλμα")
        End Try
    End Sub


And here is the result :

http://i60.tinypic.com/28gwf83.jpg[^]

The column Active value is 1.
The problem is that column Active values are missing (red values in image).
How can i fix that ?

Thanks in advance
Posted
Comments
Kornfeld Eliyahu Peter 19-Mar-15 11:48am    
Why the nested SELECT? It adds nothing...
It should be simply this:
SELECT Improve, Price, Active, Idate, ROW_NUMBER() OVER (PARTITION BY Price ORDER BY Price) AS rn
FROM tblImprove
WHERE rn = 1
jomachi 19-Mar-15 13:05pm    
Thank yoy my friend for the responce
Without it query don't work
Maciej Los 19-Mar-15 13:09pm    
Inspect your data... We can't see your screen or data.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900