⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.vb

📁 Beginning VB.NET DatabasesAll_Code.rar
💻 VB
字号:
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    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

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents ListView1 As System.Windows.Forms.ListView
    Friend WithEvents OleDbDataAdapter1 As System.Data.OleDb.OleDbDataAdapter
    Friend WithEvents OleDbSelectCommand1 As System.Data.OleDb.OleDbCommand
    Friend WithEvents OleDbConnection1 As System.Data.OleDb.OleDbConnection
    Friend WithEvents ProductsDS1 As OleDb_Data_Wizard.ProductsDS
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.ListView1 = New System.Windows.Forms.ListView
        Me.OleDbDataAdapter1 = New System.Data.OleDb.OleDbDataAdapter
        Me.OleDbSelectCommand1 = New System.Data.OleDb.OleDbCommand
        Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection
        Me.ProductsDS1 = New OleDb_Data_Wizard.ProductsDS
        CType(Me.ProductsDS1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'ListView1
        '
        Me.ListView1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.ListView1.FullRowSelect = True
        Me.ListView1.Location = New System.Drawing.Point(0, 0)
        Me.ListView1.Name = "ListView1"
        Me.ListView1.Size = New System.Drawing.Size(480, 197)
        Me.ListView1.TabIndex = 0
        Me.ListView1.View = System.Windows.Forms.View.Details
        '
        'OleDbDataAdapter1
        '
        Me.OleDbDataAdapter1.SelectCommand = Me.OleDbSelectCommand1
        Me.OleDbDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "Products", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("ProductID", "ProductID"), New System.Data.Common.DataColumnMapping("ProductName", "ProductName"), New System.Data.Common.DataColumnMapping("ProductDescription", "ProductDescription"), New System.Data.Common.DataColumnMapping("UnitPrice", "UnitPrice")})})
        '
        'OleDbSelectCommand1
        '
        Me.OleDbSelectCommand1.CommandText = "SELECT ProductID, ProductName, ProductDescription, UnitPrice FROM Products ORDER " & _
        "BY ProductName"
        Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1
        '
        'OleDbConnection1
        '
        Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
        "ocking Mode=1;Jet OLEDB:Database Password=;Data Source=""C:\Program Files\Microso" & _
        "ft Visual Studio .NET 2003\SDK\v1.1\QuickStart\aspplus\samples\grocertogo\data\g" & _
        "rocertogo.mdb"";Password=;Jet OLEDB:Engine Type=5;Jet OLEDB:Global Bulk Transacti" & _
        "ons=1;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SF" & _
        "P=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:New Database Passwor" & _
        "d=;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact" & _
        "=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:En" & _
        "crypt Database=False"
        '
        'ProductsDS1
        '
        Me.ProductsDS1.DataSetName = "ProductsDS"
        Me.ProductsDS1.Locale = New System.Globalization.CultureInfo("en-US")
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(480, 197)
        Me.Controls.Add(Me.ListView1)
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "OleDb Data Wizard"
        CType(Me.ProductsDS1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

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

        'Call LoadGenericDataSet()
        Call LoadSpecificDataSet()
    End Sub

    Private Sub LoadGenericDataSet()
        'Declare variables 
        Dim intRowIndex As Integer
        Dim intColIndex As Integer
        Dim objListViewItem As ListViewItem

        'Process column headers 
        For intColIndex = 0 To ProductsDS1.Tables(0).Columns.Count - 1
            'Add the column to the listview control 
            ListView1.Columns.Add(ProductsDS1.Tables(0).Columns(intColIndex).ColumnName, 60, HorizontalAlignment.Left)
        Next intColIndex

        'Process data 
        For intRowIndex = 0 To ProductsDS1.Tables(0).Rows.Count - 1
            'Create a new listview item 
            objListViewItem = New ListViewItem
            'Add the data to the listview item 
            objListViewItem.Text = ProductsDS1.Tables(0).Rows(intRowIndex).Item(0)
            'Add the sub items to the listview item 
            For intColIndex = 1 To ProductsDS1.Tables(0).Columns.Count - 1
                objListViewItem.SubItems.Add(ProductsDS1.Tables(0).Rows( _
                    intRowIndex).Item(intColIndex))
            Next intColIndex
            'Add the listview item to the listview control 
            ListView1.Items.Add(objListViewItem)
        Next intRowIndex

        'Autosize the columns
        For intColIndex = 0 To ProductsDS1.Tables(0).Columns.Count - 1
            ListView1.Columns(intColIndex).Width = -1
        Next intColIndex

        'Cleanup 
        objListViewItem = Nothing
    End Sub

    Private Sub LoadSpecificDataSet()
        'Declare variables
        Dim intRowIndex As Integer
        Dim objListViewItem As ListViewItem

        'Create Column Headers
        ListView1.Columns.Add( _
            ProductsDS1.Tables("Products").Columns("ProductID").ColumnName, 60, HorizontalAlignment.Left)
        ListView1.Columns.Add("Product Name", 150, HorizontalAlignment.Left)
        ListView1.Columns.Add("Product Description", 200, HorizontalAlignment.Left)
        ListView1.Columns.Add("Unit Price", 60, HorizontalAlignment.Right)

        'Process data
        For intRowIndex = 0 To ProductsDS1.Tables("Products").Rows.Count - 1
            'Create a new listview item
            objListViewItem = New ListViewItem
            'Add the data to the listview item
            objListViewItem.Text = ProductsDS1.Tables( _
                "Products").Rows(intRowIndex).Item("ProductID")
            'Add the sub items to the listview item
            objListViewItem.SubItems.Add(ProductsDS1.Tables( _
                "Products").Rows(intRowIndex).Item("ProductName"))
            objListViewItem.SubItems.Add(ProductsDS1.Tables( _
                "Products").Rows(intRowIndex).Item("ProductDescription"))
            objListViewItem.SubItems.Add(Format(ProductsDS1.Tables( _
                "Products").Rows(intRowIndex).Item("UnitPrice"), "c"))
            'Add the listview item to the listview control
            ListView1.Items.Add(objListViewItem)
        Next intRowIndex

        'Cleanup
        objListViewItem = Nothing
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -