VB2008.NET DataGrid相关总结1

前端之家收集整理的这篇文章主要介绍了VB2008.NET DataGrid相关总结1前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

VB2008.NET DataGrid相关总结1

1。DataGrid是VB6.0里的。如果VB2008中要用必须先添加ActiveX控件。

VB.net中右键工具箱,选择

2.连接数据库代码

Access数据库

Public Class Form1

    Inherits System.Windows.Forms.Form


    Dim Con As New ADODB.Connection()

    Dim Rec As New ADODB.Recordset()

    Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load

        Con.ConnectionString = "Dbq=" & Application.StartupPath & "/Test.mdb;Driver={Microsoft Access Driver (*.mdb)}"

        Con.Open()

        Rec.CursorType = 1

        Rec.LockType = 3

        Rec.ActiveConnection = Con

        Rec.Open("Student") '("Select * From Student",Con)

        AxDataGrid1.DataSource = Rec

        AxDataGrid1.Refresh()

    End Sub

    Private Sub Form1_Leave(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Leave

        Rec.Close()

        Con.Close()

        Rec = Nothing

        Con = Nothing

    End Sub

End Class

3.运行程序后

猜你在找的VB相关文章