0
Imports MySql.Data.MySqlClient
Public Class daftar
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Cn As New MySqlConnection
Dim str As String
Dim dt As New DataTable
Dim cmd As New MySqlCommand
Cn = New MySqlConnection("server=localhost;" _
& "user id=root;" _
& "password=;" _
& "database=loginapp")
Try
Cn.Open()
MsgBox("Connected")
Catch ex As Exception
MsgBox("Failed Connection " & vbCrLf & "Error Message : " & ex.Message, MsgBoxStyle.Critical, "Peringatan")
End Try
cmd.Parameters.AddWithValue("@id", user.Text)
cmd.Parameters.AddWithValue("@pass", pass.Text)
str = "INSERT INTO tbluser(Username,Password) VALUES (@id,@pass)"
cmd = New MySqlCommand(str)
cmd.ExecuteNonQuery()
MessageBox.Show("Insert Data Siswa Berhasil Dilakukan")
Cn.Close()
End Sub
End Class
我有「cmd.ExecuteNonQuery」問題開放,它有一個消息「連接必須是有效的,公開」可有人能幫助我解決這個問題?連接必須是有效的,並在2008年VB
您沒有將您的打開連接分配給您的命令。 – InbetweenWeekends
將密碼信息作爲純文本傳遞不是一個好主意。 – OneFineDay