#2
不说也罢2016-11-22 08:53
|
请各位大侠帮我看看一下代码,数据添加提示成功,但数据库记录无变化,原因在哪里?
Private Sub btnOk1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk1.Click
Cnn.ConnectionString =
= "Select 用户名,密码,职务 From tb_user WHERE 用户名='" & txtUsername.Text & "'"
Cmd.Connection = Cnn
DBAdapter.SelectCommand = Cmd
Dim builder As OleDb.OleDbCommandBuilder = New OleDb.OleDbCommandBuilder(DBAdapter)
Cnn.Open()
If txtUsername.Text = "" Or txtPwd.Text = "" Or postComboBox.Text = "" Then
Cnn.Close()
MsgBox("请填写完整信息!", MsgBoxStyle.Exclamation, "消息框")
ElseIf Cmd.ExecuteReader.Read Then
Cnn.Close()
MsgBox("用户 [ " & txtUsername.Text & " ] 已存在,请重新输入。", vbOKOnly, "系统提示")
Else
Cnn.Close()
Dim response As MsgBoxResult
response = MsgBox("确定要添加该用户吗?", vbOKCancel + vbQuestion, "系统提示")
If response = MsgBoxResult.Ok Then ' 用户选择“确定”
'添加用户信息
AddUser()
txtUsername.Clear()
txtPwd.Clear()
postComboBox.Text = ""
Else
Exit Sub
End If
End If
End Sub
Sub AddUser()
Dim SQLString As String
SQLString = "INSERT INTO tb_user VALUES('" & txtUsername.Text & "','" & txtPwd.Text & "','" & postComboBox.Text & "')"
Cnn.Open()
Cmd = New OleDbCommand(SQLString, Cnn)
Cmd.ExecuteNonQuery()
MessageBox.Show("添加成功!")
Cnn.Close()
Cnn.Dispose()
End Sub