DataGrid绑定数据

时间:2006/4/13 12:36:09      阅读:2587     附件: DataGridPage.rar (经验值:0)     下载:8
以下是代码片段:
    '绑定数据表到DataGrid(http://web3.cn)
    Sub BindData()
        Dim dv As DataView
        dv = GetNewsInfo().DefaultView
        LblNum.Text = "(共" & dv.Table.Rows.Count & "条信息)"
        dgdData.DataSource = dv
        Try
            dgdData.DataBind()
        Catch '防止分页错误(http://web3.cn)
            dgdData.CurrentPageIndex = dgdData.PageCount - 1
            dgdData.DataBind()
        End Try
    End Sub
    '读取数据库,返回数据表(http://web3.cn)
    Public Function GetNewsInfo() As DataTable
        Dim sql As String
        sql = "select * from News order by ID desc"
        Dim ds As New DataSet
        Dim conn As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & Server.MapPath("db.mdb"))
        conn.Open()
        Dim da As New OleDbDataAdapter
        da.SelectCommand = New OleDbCommand
        da.SelectCommand.Connection = conn
        da.SelectCommand.CommandText = sql
        da.Fill(ds, "News")
        conn.Close()
        Return ds.Tables(0)
    End Function
评论
  • Re:DataGrid绑定数据  (2006/8/11 16:12:40) by 飘萍 
    正在学写这个。。。。好!
标 题:
 
姓 名:
 
主 页:

验证码:

评论:
 

Because of the cache,you may see your comments several minutes later.