我有一个名为PriceTesting
的数据库(使用Microsoft Access 2007),其中包含一个名为tbl_order
的表,其中包含以下列:
Order_ID, Customer_Name, Dress_Type, Dress_Price, Quantity, Date_Of_Pickup, Payment_Status
我已成功使用以下代码将数据显示到datagridview: -
Private Sub dgvReportShow()
Dim con As New OleDb.OleDbConnection
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\annonymous\Documents\Visual Studio 2012\Projects\TMS Final\TMS Final\db\db_TMS.accdb"
If Not con.State = ConnectionState.Open Then
con.Open()
End If
Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
Dim da As New OleDb.OleDbDataAdapter
da = New OleDb.OleDbDataAdapter("SELECT Order_ID, Customer_Name, Dress_Type, Dress_Price, Quantity, Date_Of_Pickup, Payment_Status, Dress_Price * Quantity as Total " & _
"FROM tbl_order " & _
"WHERE (Payment_Status = 'paid') ", con)
da.Fill(dt)
dgvReport.DataSource = dt.DefaultView
dgvReport.SelectionMode = DataGridViewSelectionMode.FullRowSelect
End Sub
Date_Of_Pickup
在datagridview中显示为28-Dec-13
(sry ......我没有足够的意义发布快照)
现在我添加了一个包含月份的comboboxMonth
(1月,2月,3月,......等等)
这样我就可以在comboboxMonth
如何将" 28-Dec-13 "
转换为月份,以便我可以添加
" WHERE (Payment_Status = 'paid') AND Date_Of_Pickup = comboboxMonth.value "
任何人都可以帮我解决这个问题吗?
答案 0 :(得分:0)
如果您使用升序顺序(1月1日,2月2日等)手动填充您的组合月份名称,您可以在您的SelectedIndexChanged事件中写下类似这样的事件
Private Sub cbo_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles comboBoxMonths.SelectedIndexChanged
Dim cbo = CType(sender, ComboBox)
Dim monthIndex = cbo.SelectedIndex
if monthIndex <> -1 then
Dim cmdText = "SELECT Order_ID, Customer_Name, Dress_Type, Dress_Price, Quantity, " & _
"Date_Of_Pickup, Payment_Status, Dress_Price * Quantity as Total " & _
"FROM tbl_order WHERE (Payment_Status = 'paid') AND " & _
"Month(Date_Of_Pickup) = " & (monthIndex + 1).ToString
.......
End if
End Sub