【发布时间】:2014-02-15 16:18:05
【问题描述】:
嘿,我正在做一个学校项目,遇到了一些问题
我正在尝试制作更改密码表单。我有一个名为“tblLogin”的访问表,其中包含用户名、密码、SecQuest、SecAns、级别等列。
用户名是一个公共变量,属于我的登录表单
程序目前没有改变tblLogin表中密码的值
我认为这是我的 INSERT INTO 语句的问题
提前感谢您提供的任何帮助!
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim sql As String
Dim Conn As New OleDb.OleDbConnection("PROVIDER = Microsoft.ACE.OLEDB.12.0;Data Source = C:\Users\Nelson\Documents\SystemDB\DB.accdb")
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim response As Integer
Try
Conn.Open()
'establishes communication with the database
sql = "SELECT Password FROM tblLogin WHERE Username = """ & LoginForm.username & """"
'declares SQL statement
da = New OleDb.OleDbDataAdapter(sql, Conn)
'runs sql statement on database
da.Fill(ds, "passwordcheck")
'fills in a dataset called "passwordcheck" with infomation selected by the sql statement
If TextBox1.Text = TextBox2.Text And TextBox3.Text = TextBox4.Text And TextBox1.Text = ds.Tables("passwordcheck").Rows(0).Item(0) And TextBox1.Text <> "" And TextBox2.Text <> "" And TextBox3.Text <> "" And TextBox4.Text <> "" Then
response = MessageBox.Show("Are you sure?", "Attention", MessageBoxButtons.YesNo)
If response = MsgBoxResult.Yes Then
Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand("INSERT INTO tblLogin Password VALUES (?) WHERE Username = """ & LoginForm.username & """", Conn)
cmd.Parameters.Add("@Password", OleDb.OleDbType.VarChar).Value = TextBox3.Text
Conn.Close()
End If
Else
MessageBox.Show("Passwords entered are incorrect", "Attention")
End If
Catch ex As Exception
MessageBox.Show("Passwords entered are incorrect", "Attention")
End Try
End Sub
【问题讨论】:
标签: vb.net vba validation ms-access insert