Job 1
ให้นักศึกษาสร้าง From
Login ตามต้องการโดยตกแต่งให้สวยงาม จากนั้นให้ทำการเขียน Code
เพื่อทำการเชื่อมต่อฐานข้อมูลโดยวันนี้จะใช้ Microsoft
Access 2003
· สิ่งที่นักศึกษาจะได้ทำการเรียนรู้
1.
การ Import
2.
การประกาศตัวแปรเพื่อทำการรับค่าต่างๆ
3.
การเขียนโปรแกรมแบบการใช้ Function
เพื่อเรียกใช้
4.
และการกำหนด Properties
ต่างให้กับเครื่องมือที่ใช้
--------------------------------------------------------------------------------------------------
Imports System
Imports
System.Data
Imports
System.Math
Imports
System.Data.OleDb
Imports
System.Windows.Forms.VisualStyles.VisualStyleElement
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
PublicClass frmLogin
Private CN As OleDbConnection = New
OleDbConnection
Private DA As OleDbDataAdapter = New
OleDbDataAdapter
Private DS As DataSet = New
DataSet
Dim strSQL AsString
Dim Max As String = System.Environment.CurrentDirectory &"\DatabaseMax.mdb"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
PrivateSub
btnLogin_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
btnLogin.Click
Try
If
(txtUser.Text = "") Then
ErrorLog.SetError(txtUser, "Please enter User name")
ExitSub
EndIf
If
(txtPass.Text = "") Then
ErrorLog.SetError(txtPass, "Please enter Password")
ExitSub
EndIf
If
txtUser.Text <>""And txtPass.Text <>""Then
CN = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source="& Max)
CN.Open()
strSQL = "Select * From Login Where User='"&
txtUser.Text &"' and Pass='"& txtPass.Text &"'"
DA = New
OleDbDataAdapter(strSQL, CN)
DA.Fill(DS, "Login")
If DS.Tables("Login").Rows.Count > 0 Then
txtUser.Clear()
txtPass.Clear()
frmMenu.Show()
Me.Hide()
Else
MsgBox("ไม่สามารถเข้าระบบได้เนื่องจากชื่อผู้ใช้งานหรือรหัสผ่านไม่ถูกต้อง")
txtUser.Clear()
txtPass.Clear()
txtUser.Focus()
EndIf
EndIf
Catch ex As Exception
MsgBox(ex.Message)
EndTry
EndSub
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
PrivateSub
btnCancel_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
btnCancel.Click
Me.Close()
EndSub
ไม่มีความคิดเห็น:
แสดงความคิดเห็น