frm_updatelostbook.vb

来自「是关于图书管理系统的用vb.net 和access开发的」· VB 代码 · 共 94 行

VB
94 行
字号
Imports System.Data.OleDb

Public Class frm_UpdateLostBook

    Dim myConnection As New OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; Data source=D:\library.mdb")
    Dim myCommand As OleDbCommand
    Dim myReader As OleDbDataReader

    Dim dataset1 As DataSet
    Dim dataAd As OleDbDataAdapter

    Private Sub isbntxt_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ISBNtxt.KeyPress

        Dim isbn As String = ""
        Dim status As String = ""

        If e.KeyChar = ChrW(System.Windows.Forms.Keys.Enter) Then

            dataset1 = New DataSet("dataset1")
            dataAd = New OleDbDataAdapter()

            myConnection.Open()

            myCommand = New OleDbCommand("select * from BookDetails where isbn= '" & ISBNtxt.Text & "'", myConnection)

            myReader = myCommand.ExecuteReader()


            While myReader.Read
                isbn = myReader("ISBN")
                status = myReader("Status")
            End While

            If isbn = "" Then
                MsgBox("This book is not in the database yet!")

                myReader.Close()
                myConnection.Close()
                myCommand.Dispose()

                Exit Sub
            End If

            If status <> "Lost" Then
                MsgBox("This book is not lost!")

                myReader.Close()
                myConnection.Close()
                myCommand.Dispose()

                Exit Sub
            End If




            myReader.Close()

            dataAd.SelectCommand = myCommand
            dataAd.Fill(dataset1, "BookDetails")

            DataGridView1.DataSource = dataset1

            DataGridView1.DataMember = "BookDetails"

            myConnection.Close()
            myCommand.Dispose()

        End If

    End Sub

    Private Sub addbt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addbt.Click
        changeBookStatus()
    End Sub

    Sub changeBookStatus()
        myConnection.Open()

        myCommand = New OleDbCommand("Update BookDetails set Status= 'InLib',LibDate=#" & Date.Today.ToShortDateString & "# where ISBN='" & ISBNtxt.Text & "'", myConnection)

        myCommand.ExecuteNonQuery()

        myConnection.Close()
        myCommand.Dispose()
        myReader.Close()

        MsgBox("Add Success!")
    End Sub

    Private Sub exitbt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitbt.Click
        Me.Close()
    End Sub
End Class

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?