Sub Page_Load(sender As Object, e As EventArgs) DataList1.DataSource = CreateDataView( "data.mdb", "guestbook" ) DataList1.DataBind() End Sub
Function CreateDataView( Db As String, Table As String ) As DataView Dim PRovider, ConnStr, SQL As String Provider = "Microsoft.Jet.OLEDB.4.0;" ConnStr = "Provider=" & Provider & _ "Data Source=" & Server.MapPath( Db ) Dim Cmd As ADODataSetCommand Cmd = New ADODataSetCommand( "Select * from " & Table &" Order By post_time DESC", ConnStr ) Dim ds As DataSet = new DataSet() Cmd.FillDataSet(ds, Table) CreateDataView = new DataView(ds.Tables(Table)) End Function
Sub DataList_ItemCommand(sender As Object, e As DataListCommandEventArgs) select case e.CommandSource.Text case "我要发言" foot.Visible = true
case "管理留言"
case "查看详细内容" DataList1.SelectedIndex = e.Item.ItemIndex '查看留言模版被选中 case "关闭" DataList1.SelectedIndex = -1 end select DataList1.DataSource = CreateDataView( "data.mdb", "guestbook" ) DataList1.DataBind() End Sub Sub LinkButton2_Click(sender As Object, e As EventArgs) foot.Visible = false End Sub
Sub LinkButton1_Click(sender As Object, e As EventArgs) Dim ConnStr, SQL As String SQL = "Insert Into GuestBook (userName,post_time,content) Values ('"& Username.Value &"','"& DateTime.Now &"','"& Content.Value &"')" ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & Server.MapPath( "data.mdb" ) Dim Cmd As ADOCommand = New ADOCommand( SQL, ConnStr ) Cmd.ActiveConnection.Open() Cmd.Execute() Message.InnerHtml = "<B>留言成功!</B>" foot.Visible = false Page.Navigate("temp.aspx") End Sub </script>