-4
Dim okToadd As MsgBoxResult = MsgBox("Are you sure you want to add the current record?", MsgBoxStyle.YesNo)
If okToadd = MsgBoxResult.Yes Then
MsgBox("Admin information Added Sucessfully", MsgBoxStyle.OkOnly)
provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
'Change the following to your access database location
dataFile = "C:\Users\talha\Documents\login.accdb"
connString = provider & dataFile
myConnection.ConnectionString = connString
myConnection.Open()
Dim str As String
str = "insert into loginusers ([username], [password], [firstname], [lastname]) values (?, ?, ?, ?)"
Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
cmd.Parameters.Add(New OleDbParameter("username", CType(TextBox1.Text, String)))
cmd.Parameters.Add(New OleDbParameter("password", CType(TextBox2.Text, String)))
cmd.Parameters.Add(New OleDbParameter("firstname", CType(TextBox3.Text, String)))
cmd.Parameters.Add(New OleDbParameter("lastname", CType(TextBox4.Text, String)))
Try
cmd.ExecuteNonQuery()
cmd.Dispose()
myConnection.Close()
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
DataGridView1.Refresh()
Catch ex As Exception
DataGridView1.Refresh()
MsgBox(ex.Message)
DataGridView1.Refresh()
End Try
ElseIf okToadd = MsgBoxResult.No Then
End If
먼저 삽입을 시도하기 전에 "성공"메시지 상자를 표시하면 안됩니다. 삽입이 실패하고 이미 사용자에게 작동했다고 말한 경우 어떻게됩니까? 둘째, 액세스 DB에 대한 SQL 병합 기능이 없으므로 사용자 이름이 이미 있는지 확인하기위한 쿼리를 추가하고 그렇지 않은 경우에만 삽입하거나 사용자 이름을 테이블의 기본 키로 만들고 삽입해야합니다 기본 키 제약 조건 위반을 읽을 try-catch에서 – soohoonigan