📄 frm_addreader.vb
字号:
Imports System.Data.OleDb
Public Class frm_AddReader
Dim myConnection As New OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; Data source=D:\library.mdb")
Dim myCommand As OleDbCommand
Dim myReader As OleDbDataReader
Private Sub okbt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles okbt.Click
If Trim(readerNotxt.Text) = "" Then
displayMsg("User ID can not be empty")
Exit Sub
End If
If Trim(nameTxt.Text) = "" Then
displayMsg("User name can not be empty")
Exit Sub
End If
If Trim(passwordtxt.Text) = "" Then
displayMsg("User password can not be empty")
Exit Sub
End If
If checkIfAreadyExists(readerNotxt.Text) = False Then
displayMsg("User has already existed")
Exit Sub
Else
addUser()
displayMsg("add successful")
End If
End Sub
Sub displayMsg(ByVal msg As String)
MsgBox(msg, MsgBoxStyle.Information, "libarary management system")
End Sub
Function checkIfAreadyExists(ByVal id) As Boolean
Dim temp As String
temp = ""
myConnection.Open()
myCommand = New OleDbCommand("select * from SystemUsers where userID='" & id & "'", myConnection)
myReader = myCommand.ExecuteReader()
While myReader.Read
temp = myReader.Read()
End While
myConnection.Close()
myCommand.Dispose()
myReader.Close()
If temp <> id Then
Return True
Else
Return False
End If
End Function
Sub addUser()
myConnection.Open()
myCommand = New OleDbCommand("INSERT INTO ReaderDetails VALUES('" & _
readerNotxt.Text & "','" & typecombo.SelectedText & "','" & passwordtxt.Text & "','" & _
nametxt.Text & "','" & addresstxt.Text & "','" & phonetxt.Text & "','" & emailtxt.Text & _
"','" & sexcombo.SelectedText & "')", myConnection)
myCommand.ExecuteNonQuery()
myConnection.Close()
myCommand.Dispose()
End Sub
Private Sub userIdTxt_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles readerNotxt.TextChanged
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -