📄 form1.vb
字号:
Imports System.Data
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
'Initialize a new instance of the data access base class
Using objData As New WDABase
Try
'Declare local variables
Dim objDataTable As New DataTable("Projects")
'Get all Projects in a DataSet
objData.SQL = "SELECT ProjectID, ProjectName " & _
"FROM vw_SelectProjects " & _
"ORDER BY ProjectName"
objData.InitializeCommand()
Call objData.FillDataTable(objDataTable)
'Bind ListBox control
ListBox1.DataSource = objDataTable
ListBox1.DisplayMember = "ProjectName"
ListBox1.ValueMember = "ProjectID"
Catch ExceptionErr As Exception
MessageBox.Show(ExceptionErr.Message, "Exercise 1")
End Try
End Using
End Sub
Private Sub ListBox1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles ListBox1.Click
'Initialize a new instance of the data access base class
Using objData As New WDABase
Try
'Build the SQL string
objData.SQL = "SELECT ProjectDescription " & _
"FROM vw_SelectProjects " & _
"WHERE ProjectID = @ProjectID"
'Initialize the Command object
objData.InitializeCommand()
'Add a Parameter to the Parameters collection
objData.AddParameter("@ProjectID", _
Data.SqlDbType.UniqueIdentifier, 16, ListBox1.SelectedValue)
'Open the connection
objData.OpenConnection()
'Get the data in a DataReader object
objData.DataReader = objData.Command.ExecuteReader
'See if any data exists before continuing
If objData.DataReader.HasRows Then
'Read the first row
objData.DataReader.Read()
'Populate the fields on the form
txtProjectDescription.Text = _
objData.DataReader.Item("ProjectDescription")
End If
'Close the DataReader
objData.DataReader.Close()
'Close the database connection
objData.CloseConnection()
Catch ExceptionErr As Exception
MessageBox.Show(ExceptionErr.Message, "Exercise 1")
End Try
End Using
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -