📄 transactions.vb
字号:
Public Class frmTransactions
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
Friend WithEvents cnAccessNwind As System.Data.OleDb.OleDbConnection
Friend WithEvents daOrders As System.Data.OleDb.OleDbDataAdapter
Friend WithEvents cmdSelectOrders As System.Data.OleDb.OleDbCommand
Friend WithEvents cmdInsertOrders As System.Data.OleDb.OleDbCommand
Friend WithEvents daCustomers As System.Data.OleDb.OleDbDataAdapter
Friend WithEvents cmdInsertCustomers As System.Data.OleDb.OleDbCommand
Friend WithEvents cmdSelectCustomers As System.Data.OleDb.OleDbCommand
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents lbCustomers As System.Windows.Forms.ListBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents btnLoad As System.Windows.Forms.Button
Friend WithEvents dgOrders As System.Windows.Forms.DataGrid
Friend WithEvents btnCreate As System.Windows.Forms.Button
Friend WithEvents btnNested As System.Windows.Forms.Button
Friend WithEvents btnCommit As System.Windows.Forms.Button
Friend WithEvents btnRollback As System.Windows.Forms.Button
'Required by the Windows Form Designer
Private components As System.ComponentModel.Container
'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 dsCustomerOrders1 As WindowsApplication1.dsCustomerOrders
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.btnRollback = New System.Windows.Forms.Button()
Me.daCustomers = New System.Data.OleDb.OleDbDataAdapter()
Me.cmdInsertCustomers = New System.Data.OleDb.OleDbCommand()
Me.cnAccessNwind = New System.Data.OleDb.OleDbConnection()
Me.cmdSelectCustomers = New System.Data.OleDb.OleDbCommand()
Me.btnCommit = New System.Windows.Forms.Button()
Me.Label2 = New System.Windows.Forms.Label()
Me.cmdSelectOrders = New System.Data.OleDb.OleDbCommand()
Me.btnLoad = New System.Windows.Forms.Button()
Me.dgOrders = New System.Windows.Forms.DataGrid()
Me.dsCustomerOrders1 = New WindowsApplication1.dsCustomerOrders()
Me.btnCreate = New System.Windows.Forms.Button()
Me.lbCustomers = New System.Windows.Forms.ListBox()
Me.daOrders = New System.Data.OleDb.OleDbDataAdapter()
Me.cmdInsertOrders = New System.Data.OleDb.OleDbCommand()
Me.btnNested = New System.Windows.Forms.Button()
Me.Label1 = New System.Windows.Forms.Label()
CType(Me.dgOrders, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.dsCustomerOrders1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'btnRollback
'
Me.btnRollback.Location = New System.Drawing.Point(304, 136)
Me.btnRollback.Name = "btnRollback"
Me.btnRollback.Size = New System.Drawing.Size(96, 23)
Me.btnRollback.TabIndex = 7
Me.btnRollback.Text = "Rollback"
'
'daCustomers
'
Me.daCustomers.InsertCommand = Me.cmdInsertCustomers
Me.daCustomers.SelectCommand = Me.cmdSelectCustomers
Me.daCustomers.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "CustomerList", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("CustomerID", "CustomerID"), New System.Data.Common.DataColumnMapping("CompanyName", "CompanyName"), New System.Data.Common.DataColumnMapping("FullID", "FullID")})})
'
'cmdInsertCustomers
'
Me.cmdInsertCustomers.CommandText = "INSERT INTO Customers (CompanyName, CustomerID) VALUES (?, ?)"
Me.cmdInsertCustomers.Connection = Me.cnAccessNwind
Me.cmdInsertCustomers.Parameters.Add(New System.Data.OleDb.OleDbParameter("CompanyName", System.Data.OleDb.OleDbType.Char, 40, "CompanyName"))
Me.cmdInsertCustomers.Parameters.Add(New System.Data.OleDb.OleDbParameter("CustomerID", System.Data.OleDb.OleDbType.Char, 5, "CustomerID"))
'
'cnAccessNwind
'
Me.cnAccessNwind.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=" & _
"C:\adonetsbs\SampleDBs\nwind.mdb;" & _
"Mode=Share Deny None;Extended Properties="""";Jet OLEDB:System database="""";Jet OLE" & _
"DB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=5;Jet O" & _
"LEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Globa" & _
"l Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System" & _
" Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on " & _
"Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False" & _
""
'
'cmdSelectCustomers
'
Me.cmdSelectCustomers.CommandText = "SELECT CompanyName, CustomerID, FullID FROM CustomerList"
Me.cmdSelectCustomers.Connection = Me.cnAccessNwind
'
'btnCommit
'
Me.btnCommit.Location = New System.Drawing.Point(304, 104)
Me.btnCommit.Name = "btnCommit"
Me.btnCommit.Size = New System.Drawing.Size(96, 23)
Me.btnCommit.TabIndex = 6
Me.btnCommit.Text = "Commit"
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label2.Location = New System.Drawing.Point(8, 128)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(43, 13)
Me.Label2.TabIndex = 0
Me.Label2.Text = "Orders:"
'
'cmdSelectOrders
'
Me.cmdSelectOrders.CommandText = "SELECT OrderID, CustomerID, OrderDate FROM Orders"
Me.cmdSelectOrders.Connection = Me.cnAccessNwind
'
'btnLoad
'
Me.btnLoad.Location = New System.Drawing.Point(304, 8)
Me.btnLoad.Name = "btnLoad"
Me.btnLoad.Size = New System.Drawing.Size(96, 23)
Me.btnLoad.TabIndex = 3
Me.btnLoad.Text = "Load Data"
'
'dgOrders
'
Me.dgOrders.DataMember = "CustomerList.CustomerListOrders"
Me.dgOrders.DataSource = Me.dsCustomerOrders1
Me.dgOrders.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.dgOrders.Location = New System.Drawing.Point(8, 144)
Me.dgOrders.Name = "dgOrders"
Me.dgOrders.Size = New System.Drawing.Size(280, 128)
Me.dgOrders.TabIndex = 2
'
'dsCustomerOrders1
'
Me.dsCustomerOrders1.DataSetName = "dsCustomerOrders"
Me.dsCustomerOrders1.Locale = New System.Globalization.CultureInfo("en-US")
Me.dsCustomerOrders1.Namespace = "http://www.tempuri.org/dsCustomerOrders.xsd"
'
'btnCreate
'
Me.btnCreate.Location = New System.Drawing.Point(304, 40)
Me.btnCreate.Name = "btnCreate"
Me.btnCreate.Size = New System.Drawing.Size(96, 23)
Me.btnCreate.TabIndex = 4
Me.btnCreate.Text = "Create"
'
'lbCustomers
'
Me.lbCustomers.DataSource = Me.dsCustomerOrders1.CustomerList
Me.lbCustomers.DisplayMember = "FullID"
Me.lbCustomers.Location = New System.Drawing.Point(8, 24)
Me.lbCustomers.Name = "lbCustomers"
Me.lbCustomers.Size = New System.Drawing.Size(280, 95)
Me.lbCustomers.TabIndex = 1
Me.lbCustomers.ValueMember = "CustomerID"
'
'daOrders
'
Me.daOrders.InsertCommand = Me.cmdInsertOrders
Me.daOrders.SelectCommand = Me.cmdSelectOrders
Me.daOrders.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "Orders", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("OrderID", "OrderID"), New System.Data.Common.DataColumnMapping("CustomerID", "CustomerID"), New System.Data.Common.DataColumnMapping("OrderDate", "OrderDate")})})
'
'cmdInsertOrders
'
Me.cmdInsertOrders.CommandText = "INSERT INTO Jan01Orders (CustomerID, OrderDate) VALUES (?, ?)"
Me.cmdInsertOrders.Connection = Me.cnAccessNwind
Me.cmdInsertOrders.Parameters.Add(New System.Data.OleDb.OleDbParameter("CustomerID", System.Data.OleDb.OleDbType.Char, 5, "CustomerID"))
Me.cmdInsertOrders.Parameters.Add(New System.Data.OleDb.OleDbParameter("OrderDate", System.Data.OleDb.OleDbType.Date, 0, "OrderDate"))
'
'btnNested
'
Me.btnNested.Location = New System.Drawing.Point(304, 72)
Me.btnNested.Name = "btnNested"
Me.btnNested.Size = New System.Drawing.Size(96, 23)
Me.btnNested.TabIndex = 5
Me.btnNested.Text = "Create Nested"
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(8, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(64, 13)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Customers:"
'
'frmTransactions
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(408, 285)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnRollback, Me.btnCommit, Me.btnNested, Me.btnCreate, Me.dgOrders, Me.btnLoad, Me.Label2, Me.lbCustomers, Me.Label1})
Me.Name = "frmTransactions"
Me.Text = "Transactions"
CType(Me.dgOrders, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.dsCustomerOrders1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
#Region "Utility Functions"
Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
Me.dsCustomerOrders1.Clear()
Me.daCustomers.Fill(Me.dsCustomerOrders1.CustomerList)
Me.daOrders.Fill(Me.dsCustomerOrders1.Orders)
End Sub
Sub AddRows(ByVal newCust As String)
Dim newRow As System.Data.DataRow
newRow = Me.dsCustomerOrders1.CustomerList.NewRow
With newRow
.Item("CompanyName") = "A New Customer Record"
.Item("CustomerID") = newCust
End With
Me.dsCustomerOrders1.CustomerList.Rows.Add(newRow)
newRow = Me.dsCustomerOrders1.Orders.NewRow
With newRow
.Item("CustomerID") = newCust
.Item("OrderDate") = Today()
End With
Me.dsCustomerOrders1.Orders.Rows.Add(newRow)
End Sub
#End Region
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -