希望大家帮帮忙,谢谢各位拉!
具体代码如下Imports System.Data.SqlClient
Public Class 密码修改
Dim mycn As New SqlConnection("Data Source =(local);Initial Catalog =教师信息管理系统;Integrated Security=SSPI")
Dim mycommand As New SqlCommand
Function DataCheck(ByVal a As String, ByVal b As String) As Boolean
mycommand.CommandText = "Select count(*) From 密码表" & _
" Where 用户名= '" & a & "'and 密码 = '" & b & "'"
mycommand.Connection = mycn
If mycommand.ExecuteScalar = 0 Then
Return True
Else
Return False
End If
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim username As String
Dim userpaw As String
username = txtusername.Text
userpaw = txtouserpaw.Text
Try
mycn.Open()
If DataCheck(username, userpaw) = True Then
MsgBox("用户名和密码不存在,请重新输入")
Else
If txtnuserpaw1.Text = txtnuserpaw2.Text Then
mycommand.CommandType = CommandType.Text
mycommand.CommandText = "Update 密码表 set 密码 =' " & txtnuserpaw2.Text.Trim & "'Where 用户名 =' " & txtusername.Text.Trim & "'"
mycommand.Connection = mycn
mycommand.ExecuteNonQuery()
MsgBox("密码修改成功!!")
Else
MsgBox("前后2次密码不一致!!")
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
mycn.Close()
End Try
End Sub