conn = New SqlConnection(ConnectionStr)
conn.Open()
If CboDesc.Text <> "" Then
DescId = CInt(Mid(CboDesc.Text, (InStrRev(CboDesc.Text, "|") + 1), Len(CboDesc.Text)))
Else
DescId = 0
End If
sql = " Select a.Type,a.Description,b.DescId,b.Rate,b.EffTo,b.EffFrom from DescriptionMaster a " _
& " Inner join (Select DescId,Rate,EffFrom,EffTo,LocationId," _
& " ROW_NUMBER() OVER (PARTITION BY DescId ORDER BY EffFrom DESC) rn " _
& " from RateMaster where Locationid = " & LocationId & ") b On a.TranId = b.DescId And rn = 1 " _
& " Where b.LocationId = " & LocationId & " "
'& " Group By a.Type,a.Description,b.DescId,b.Rate,b.EffTo,b.EffFrom "
If CboType.Text <> "" Then
sql = sql + "And a.Type = '" & CboType.Text & "'"
End If
If DescId <> 0 Then
sql = sql + "and "
End If
If DescId <> 0 Then
sql = sql + "b.DescId = " & DescId & ""
End If
sql = sql + "Group By a.Type,a.Description,b.DescId,b.Rate,b.EffTo,b.EffFrom "
Cmd = New SqlCommand(sql, conn)
DR = Cmd.ExecuteReader
DGVDesc.Rows.Clear()
If DR.HasRows Then
While DR.Read
DGVDesc.Rows.Add()
n = DGVDesc.RowCount - 1
DGVDesc.Rows.Item(n).Cells("Type").Value = DR.Item("Type")
DGVDesc.Rows.Item(n).Cells("Description").Value = DR.Item("Description") & "|" & DR.Item("DescId")
DGVDesc.Rows.Item(n).Cells("Rate").Value = DR.Item("Rate")
DGVDesc.Rows.Item(n).Cells("EffFrom").Value = DR.Item("EffFrom")
DGVDesc.Rows.Item(n).Cells("Effto").Value = DR.Item("EffTo")
End While
Else
MsgBox("No Records Found. Please Check...")
End If
DR.Close()
No comments:
Post a Comment