2013-12-20 127 views
0

我有一個(使用Microsoft Access 2007),其中包含一個名爲tbl_order與列的表名爲PriceTesting數據庫:顯示記錄根據月

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顯示這樣28-Dec-13在DataGridView (SRY ...我沒有足夠的點張貼快照)

現在我已經加入了comboboxMonth包含月份(一月,二月,三月,...等) ,這樣我可以通過選定月份在comboboxMonth

查看記錄如何轉換在" 28-Dec-13 "到一個月,所以我可以添加

" WHERE (Payment_Status = 'paid') AND Date_Of_Pickup = comboboxMonth.value " 

誰能幫我解決了這個問題?

+0

你怎麼填充寫組合框?只是與包含月份名稱的字符串? – Steve

+0

是嗎..我手動在表單設計中添加月份 – WaN

+0

因此,組合的第一個索引是月份1月等等? – Steve

回答

0

如果您手動填充您的組合與在ascendig順序(月份名稱一月第一,二月的第二個,等等,你可以在你的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 
+0

aaaaahh ..通過使用selectedindex呵呵..確定生病嘗試實施這...讓你知道後面的結果.. – WaN

+0

代碼的作品... tq非常..但我dun得到的部分 「昏暗的cbo = CType(發件人,組合框)」這是什麼? – WaN

+0

發件人作爲對象傳遞給事件處理程序,但我們知道這是生成事件的組合框。如果我們想要提取SelectedIndex屬性,我們需要將其轉換回適當的類型,這是CType的工作..... – Steve