日期:2008-06-26  浏览次数:20460 次

在ado.net中我们很少甚至不用recordset今天我就向大家展示如何在ado.net中使用recordset
新建一个vb.net应用程序

在窗体上添加一个datagrid控件
然后,项目-->添加引用--〉com->
选择Microsoft ActiveX Data Objects 2.7 Library
这样在引用一栏我们就看到新加入一项ADODB
我们将其与其他命名空间一起倒入
Imports System.Data
Imports System.Data.OleDb
Imports ADODB
整个代码如下(使用中文officeXp事例数据库-因为是中文所以表明字段名都是中文,你也可以利用其他的数据库)
Imports System.Data
Imports System.Data.OleDb
Imports ADODB

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '窗体重写处置以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意:以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.DataGrid1 = New System.Windows.Forms.DataGrid()
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'DataGrid1
        '
        Me.DataGrid1.DataMember = ""
        Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.DataGrid1.Location = New System.Drawing.Point(8, 8)
        Me.DataGrid1.Name = "DataGrid1"
        Me.DataGrid1.Size = New System.Drawing.Size(536, 320)
        Me.DataGrid1.TabIndex = 0
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(552, 333)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.DataGrid1})