📄 frm_edituser.vb
字号:
Imports System.Data.OleDb
Public Class frm_EditUser
Dim myConnection As New OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; Data source=D:\library.mdb")
Dim myCommand As OleDbCommand
Dim myReader As OleDbDataReader
Friend readerNo As String
Sub addToReaderCodeCombo()
myConnection.Open()
myCommand = New OleDbCommand("select * from ReaderType", myConnection)
myReader = myCommand.ExecuteReader
While myReader.Read
typeCodecombo.Items.Add(myReader("ReaderTypeCode"))
typecombo.Items.Add(myReader("Type"))
End While
myConnection.Close()
myCommand.Dispose()
myReader.Close()
End Sub
Private Sub typeCodecombo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles typeCodecombo.SelectedIndexChanged
typecombo.SelectedIndex = typeCodecombo.SelectedIndex
End Sub
Private Sub frm_EditUser_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
readernotxt.Text = readerNo
nametxt.Focus()
Dim commandStr = "select * from ReaderDetails where ReaderNo='" & readerNo & "'"
myConnection.Open()
myCommand = New OleDbCommand(commandStr, myConnection)
myReader = myCommand.ExecuteReader()
While myReader.Read
passwordtxt.Text = myReader("Password").ToString
nametxt.Text = myReader("Name").ToString
addresstxt.Text = myReader("Address").ToString
phonetxt.Text = myReader("Phone").ToString
sexcombo.Text = myReader("Sex").ToString
emailtxt.Text = myReader("Email").ToString
typeCodecombo.Text = myReader("ReaderTypeCode").ToString
End While
myConnection.Close()
myReader.Close()
myCommand.Dispose()
addToReaderCodeCombo()
typecombo.Text = setInitialType()
End Sub
Function setInitialType() As String
Dim type As String = ""
Dim commandStr = "select * from ReaderType where ReaderTypeCode='" & typeCodecombo.Text & "'"
myConnection.Open()
myCommand = New OleDbCommand(commandStr, myConnection)
myReader = myCommand.ExecuteReader()
While myReader.Read
type = myReader("Type")
End While
myConnection.Close()
myReader.Close()
myCommand.Dispose()
Return type
End Function
Private Sub savebt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles savebt.Click
If passwordtxt.Text = "" Then
MsgBox("Password can not be empty")
Exit Sub
End If
If nametxt.Text = "" Then
MsgBox("Name can not be empty")
Exit Sub
End If
If emailtxt.Text = "" Then
MsgBox("Reader type can not be empty")
Exit Sub
End If
If phonetxt.Text = "" Then
MsgBox("Reader type can not be empty")
Exit Sub
End If
If addresstxt.Text = "" Then
MsgBox("Reader type can not be empty")
Exit Sub
End If
myConnection.Open()
myCommand = New OleDbCommand("Update ReaderDetails set ReaderTypecode='" & _
typeCodecombo.Text & "',[Password]='" & passwordtxt.Text & "',Name='" & nametxt.Text & "',Address='" & _
addresstxt.Text & "',phone='" & phonetxt.Text & "',Email='" & emailtxt.Text & _
"',Sex='" & sexcombo.Text & "' where ReaderNo='" & readernotxt.Text & "'", myConnection)
Try
myCommand.ExecuteNonQuery()
MsgBox("Edit success!")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
myConnection.Close()
myCommand.Dispose()
End Sub
Private Sub closebt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles closebt.Click
Me.Close()
End Sub
Private Sub continuebt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles continuebt.Click
Me.Hide()
frm_FindEditUser.Show()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -