在部落格中查詢不同日期部落格的代碼

來源:互聯網
上載者:User

關鍵一點

在設定datasource的時候,必須先清空datasourceid,二者不能同時存在。

 

Sub date_selected()Sub date_selected(ByVal sender As Object, ByVal e As EventArgs) Handles Calendar1.SelectionChanged

        Label1.Visible = True
        Label1.Text = Calendar1.SelectedDate
        Dim con As OleDbConnection
        Dim comm As OleDbCommand
        Dim strsql As String
        Dim oda As New OleDbDataAdapter
        Dim oledata As DataSet
        Dim mytable As String
        
        
        strsql = "select [log_id],[log_Title], [log_Intro], [log_Content], [log_Author], [log_PostYear], [log_PostMonth], [log_PostDay], [log_PostTime], [log_Weather], [log_CateID], [log_From], [log_CommNums], [log_ViewNums], [log_QuoteNums], [log_IsShow] FROM [blog_Content] where [log_PostYear]=? and [log_PostMonth]=? and [log_PostDay]=? order by [log_id] desc"
        
        con = New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=" & Server.MapPath("~app_datap-blog.mdb"))
        comm = New OleDbCommand(strsql, con)
        
        comm.Parameters.AddWithValue("tyear", CInt(Year(Calendar1.SelectedDate)))
        comm.Parameters.AddWithValue("tmonth", CInt(Month(Calendar1.SelectedDate)))
        comm.Parameters.AddWithValue("tday", CInt(Day(Calendar1.SelectedDate)))
        
        
        oda.SelectCommand = comm
        oledata = New DataSet
        mytable = "blog_content"
        
        oda.Fill(oledata, mytable)
        
        GridView1.DataSourceID = ""
        
        GridView1.DataSource = oledata.Tables(mytable).DefaultView
        GridView1.DataBind()
        
        
    
    End Sub

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.