嘿傢伙我需要一些幫助我的代碼在這裏我真的不知道它在哪裏關閉連接的部分....我想要的是保持添加記錄,直到我點擊了msgbox沒有什麼關閉此連接?
繼承人我的代碼:
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
真的很感謝你的幫助
執行中是否有錯誤? – Gayatri