?? frmbookcat.vb
字號:
Imports System.Data
Imports System.Data.SqlClient
Public Class FrmBookCat
Inherits System.Windows.Forms.Form
#Region " Windows 窗體設計器生成的代碼 "
Public Sub New()
MyBase.New()
'該調用是 Windows 窗體設計器所必需的。
InitializeComponent()
'在 InitializeComponent() 調用之后添加任何初始化
End Sub
'窗體重寫 dispose 以清理組件列表。
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 lstBookCat As System.Windows.Forms.ListBox
Friend WithEvents TxtCatName As System.Windows.Forms.TextBox
Friend WithEvents BtnAdd As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.lstBookCat = New System.Windows.Forms.ListBox
Me.TxtCatName = New System.Windows.Forms.TextBox
Me.BtnAdd = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'lstBookCat
'
Me.lstBookCat.ItemHeight = 12
Me.lstBookCat.Location = New System.Drawing.Point(8, 8)
Me.lstBookCat.Name = "lstBookCat"
Me.lstBookCat.Size = New System.Drawing.Size(272, 220)
Me.lstBookCat.TabIndex = 0
'
'TxtCatName
'
Me.TxtCatName.Location = New System.Drawing.Point(8, 232)
Me.TxtCatName.Name = "TxtCatName"
Me.TxtCatName.TabIndex = 1
Me.TxtCatName.Text = "TextBox1"
'
'BtnAdd
'
Me.BtnAdd.Location = New System.Drawing.Point(120, 232)
Me.BtnAdd.Name = "BtnAdd"
Me.BtnAdd.TabIndex = 2
Me.BtnAdd.Text = "添加"
'
'FrmBookCat
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(288, 261)
Me.Controls.Add(Me.BtnAdd)
Me.Controls.Add(Me.TxtCatName)
Me.Controls.Add(Me.lstBookCat)
Me.Name = "FrmBookCat"
Me.Text = "FrmBookCat"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub FrmBookCat_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'添加到數據庫
'定義如何聯接
Dim connStr As String
connStr = "Server=BJS1;Database=BookSystem;User ID=sa;Password=;Trusted_Connection=False"
'定義一個連接對象,連接到數據庫
Dim myBookConn As New SqlConnection(connStr)
myBookConn.Open()
'定義一個執行對象,用于Sql語句執行
Dim myBookCommand As New SqlCommand("select * from bookcat")
'執行Sql語句
myBookCommand.Connection = myBookConn
'獲取數據
Dim myReader As SqlDataReader
myReader = myBookCommand.ExecuteReader(CommandBehavior.CloseConnection)
'在列表框上顯示
Do While myReader.Read
lstBookCat.Items.Add(myReader.Item("catName"))
Loop
End Sub
Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
'在界面上添加
lstBookCat.Items.Add(TxtCatName.Text)
'添加到數據庫
'定義如何聯接
Dim connStr As String
connStr = "Server=BJS1;Database=BookSystem;User ID=sa;Password=;Trusted_Connection=False"
'定義一個連接對象,連接到數據庫
Dim myBookConn As New SqlConnection(connStr)
myBookConn.Open()
'定義一個執行對象,用于Sql語句執行
Dim myBookCommand As New SqlCommand("insert into bookcat (catName) values('" + TxtCatName.Text + "')")
'執行Sql語句
myBookCommand.Connection = myBookConn
myBookCommand.ExecuteNonQuery()
myBookConn.Close()
End Sub
End Class
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -