如何在mysql中按月分组数据?

时间:2017-03-09 22:47:02

标签: mysql vb.net

我试图按月生成报告。

但是在这一行:

Dim startDate As DateTime = DateTime.Parse(datefrom)
  

字符串未被识别为有效的DateTime。

代码:

getyear = Format(Date.Now, "yyyy")
Dim rmonth As Integer = 0
Dim datefrom As String
Dim dateto As String
If cmb_rmonth.Text = "January" Then
    rmonth = 1
ElseIf cmb_rmonth.Text = "February" Then
    rmonth = 2
ElseIf cmb_rmonth.Text = "March" Then
    rmonth = 3
End If


datefrom = getyear & "-" & rmonth & "-1"
dateto = getyear & "-" & rmonth & "-31"

Dim startDate As DateTime = DateTime.Parse(datefrom)
Dim endDate As DateTime = startDate.AddMonths(1).AddDays(-1)

Call connectDB()
Dim dataset2 As New DataSet
Dim dataadapter2 As New MySqlDataAdapter(" SELECT taxi_no as 'Taxi No.', item_name as 'Item', quantity as 'Quantity', amount as 'Amount' FROM spare_parts WHERE date >= @from AND date < @to", sqlcon)
dataadapter2.SelectCommand.Parameters.AddWithValue("@from", startDate)
dataadapter2.SelectCommand.Parameters.AddWithValue("@to", endDate)

dataadapter2.Fill(dataset2, "spare_parts")
dgv_inventory.DataSource = dataset2.Tables("spare_parts")
Call disconnectDB()

0 个答案:

没有答案