xujinghao60482 2015-11-27 06:52 采纳率: 0%
浏览 1700

无法更新SQL数据库的数据 (新手问题)

小弟接触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

  • 写回答

1条回答 默认 最新

  • xujinghao60482 2015-11-27 09:46
    关注

    是基于VB.net的

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。