やあみんなここで私のコードについて助けが必要です接続を閉じる部分がどこにあるのか本当にわかりません....私が欲しいのは、msgboxからnoをクリックするまでレコードを追加し続けることです
ここに私のコードがあります:
Dim connstr As String = "server=localhost; uid= root; password=root; database=lmsdbase;"
Dim conn As MySqlConnection = New MySqlConnection
Dim ds As New DataSet
Dim da As MySqlDataAdapter
conn.ConnectionString = connstr
Try
If conn.State = ConnectionState.Closed Then
conn.Open()
Else
conn.Close()
MsgBox("Database Connection Error")
End If
Catch ex As Exception
MsgBox(Err.Description)
txtBookISBN.Focus()
End Try
Dim SqlStatement As String = "INSERT INTO tblIssue(ISBN, Title, BorrowerID, Name, Occupation, BorrowerType, School, DateIssued, DateToBeReturned) VALUES('" & txtBookISBN.Text & "','" & txtBTitle.Text & "','" & txtMemID.Text & "','" & txtMemName.Text & "','" & txtOccupation.Text & "','" & cboBtype.Text & "','" & txtSchool.Text & "','" & DateTimePicker1.Text & "','" & DateTimePicker2.Text & "')"
Save(SqlStatement)
Public Sub Save(ByRef SqlStatement As String)
Dim cmd As MySqlCommand = New MySqlCommand
With cmd
.CommandText = SqlStatement
.CommandType = CommandType.Text
.Connection = conn
.ExecuteNonQuery()
End With
'conn.Close()
MsgBox("Success!")
If MsgBox("Do You Want to Add New Record?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
txtMemID.Text = ""
txtMemName.Text = ""
txtBookISBN.Text = ""
txtBTitle.Text = ""
txtOccupation.Text = ""
cboBtype.Text = ""
txtSchool.Text = ""
txtMemID.Focus()
Else
Me.Close()
End If
conn.Dispose()
End Sub
本当にあなたの助けに感謝します