I am using the following code to return values that lay in a date range, but when I test my answer, it is wrong. It is always returning less that what it should.
I may expect to have 14 rows in the grid and only get 10
here is the code:
I may expect to have 14 rows in the grid and only get 10
here is the code:
Code:
Dim dt2 As New DataTable
If con.State = ConnectionState.Closed Then
con.Open()
End If
Dim YearSelected As String = cmbYearSelected.SelectedItem.ToString
If cmbMonth_2.Text <> "None" Then
DaysInMonth2 = DateTime.DaysInMonth(CInt(cmbYearSelected.Text), CInt(cmbMonth_2.SelectedIndex) + 1)
MonthA = (cmbYearSelected.Text & "/" & Month1 & "/01")
MonthB = cmbYearSelected.Text & "/" & Month2 & "/" & DaysInMonth2
End If
Dim JustMonth As Integer = cmbMonth_1.SelectedIndex + 1
If radDateReg.Checked = True Then
If cmbMonth_1.Text = "None" And cmbMonth_2.Text = "None" Then
'Select DateName( month , DateAdd( month , Month(DateComp) , -1 ) )
FieldString2 = "SELECT Seta , DateName( month , DateAdd( month , Month(DateComp) , -1 ) ), count(DateComp) FROM Student WHERE year(DateComp) = '" & YearSelected & "' GROUP BY seta ,Month(DateComp) "
Else
If cmbMonth_1.Text <> "None" And cmbMonth_2.Text = "None" Then
FieldString2 = "SELECT Seta , DateName( month , DateAdd( month , Month(DateComp) , -1 ) ), count(DateComp) FROM Student WHERE year(DateComp) = '" & YearSelected & "' and Month(Datecomp) = '" & JustMonth & "' GROUP BY seta, Month(DateComp) "
End If
If cmbMonth_1.Text <> "None" And cmbMonth_2.Text <> "None" Then
FieldString2 = "SELECT Seta , DateName( month , DateAdd( month , Month(DateComp) , -1 ) ), count(DateComp) FROM Student WHERE Datecomp between '" & MonthA.Date & "' and '" & MonthB.Date & "' GROUP BY seta ,Month(DateComp)"
End If
End If
Else
If cmbMonth_1.Text = "None" And cmbMonth_2.Text = "None" Then
''Select DateName( month , DateAdd( month , Month(Dateregis) , -1 ) )
FieldString2 = "SELECT Seta , DateName( month , DateAdd( month , Month(Dateregis) , -1 ) ), count(Dateregis) FROM Student WHERE year(Dateregis) = '" & YearSelected & "' GROUP BY seta ,Month(Dateregis) "
Else
If cmbMonth_1.Text <> "None" And cmbMonth_2.Text = "None" Then
FieldString2 = "SELECT Seta , DateName( month , DateAdd( month , Month(Dateregis) , -1 ) ), count(Dateregis) FROM Student WHERE year(Dateregis) = '" & YearSelected & "' and Month(Dateregis) = '" & JustMonth & "' GROUP BY seta, Month(Dateregis) "
End If
If cmbMonth_1.Text <> "None" And cmbMonth_2.Text <> "None" Then
FieldString2 = "SELECT Seta , DateName( month , DateAdd( month , Month(Dateregis) , -1 ) ), count(Dateregis) FROM Student WHERE Dateregis between'" & MonthA.Date & "' and '" & MonthB.Date & "' GROUP BY seta ,Month(Dateregis)"
End If
End If
End If
'' SQL Statement
myCommand = New SqlClient.SqlCommand(FieldString2, con)
adp2 = New SqlDataAdapter(myCommand)
adp2.Fill(dt2)
UltraGrid1.DataSource = dt2
UltraGrid1.Selected.Rows.AddRange(UltraGrid1.Rows.All)