小弟接触SQL没多久, 被这个问题折磨了很久. 希望坛友能解惑.不胜感激
其它都没问题,就是不能按我要的替换已有密码. (就是下面update那一段)
Imports System.Data
Imports System.Data.SqlClient
Public Class Form2
Dim con As SqlConnection
Dim adap As SqlDataAdapter
Dim cmd As SqlCommand
Dim ds As DataSet
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'DatabaseStaffDataSet.Password' table. You can move, or remove it, as needed.
Me.PasswordTableAdapter.Fill(Me.DatabaseStaffDataSet.Password)
con = New SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\DatabaseStaff.mdf;Integrated Security=True")
con.Open()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
adap = New SqlDataAdapter("SELECT * FROM [Password] where Username='" & Trim(ComboBox1.Text) & "'and Password = '" & Trim(TextBox1.Text) & "';", con)
ds = New DataSet()
adap.Fill(ds, "Password")
Dim count = ds.Tables("Password").Rows.Count
If count > 0 Then
If Trim(TextBox2.Text) = Trim(TextBox3.Text) And Len(TextBox2.Text) > 2 Then
cmd = New SqlCommand()
cmd.CommandText = "update Password set Password= '" & Trim(ComboBox1.Text) & "' where Username = '" & Trim(ComboBox1.Text) & "'"
cmd.Connection = con
cmd.ExecuteNonQuery()
MsgBox("Dear " & Trim(ComboBox1.Text) & ", Your password has been changed")
ElseIf Trim(TextBox2.Text) <> Trim(TextBox3.Text) Then
MsgBox("Your new passwords do not match", MsgBoxStyle.Critical)
ElseIf Len(TextBox2.Text) < 3 Then
MsgBox("New password must be at least 3 charactors", MsgBoxStyle.Critical)
End If
Else
MsgBox("Current password Wrong, please check your usename and password", MsgBoxStyle.Critical)
End If
End Sub
End Class
是基于VB.net的