大神好, 这个问题折磨我很久了还是没有等到答案.
我用下列的编程做的VB命令, 程序本身运行正常. 不过就是SQL里的更新password不能被更新.
奇怪的是当生成可执行文件.exe后, password又,没有问题. 只是在用F5调试的时候不行.Imports System.Data
Imports System.Data.SqlClientPublic 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)
End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Try
con = New SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\DatabaseStaff.mdf; Integrated Security=True") adap = New SqlDataAdapter("SELECT * FROM [Password] where Username='" & Trim(ComboBox1.Text) & "'and Pwd = '" & 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 pwd= '" & Trim(TextBox2.Text) & "' where Username = '" & Trim(ComboBox1.Text) & "'"
MsgBox(cmd.CommandText)
cmd.Connection = con
con.Open()
cmd.ExecuteNonQuery()
con.Close()
''???????????????
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
Catch ex As Exception
MessageBox.Show(ex.Message) End Try End Sub
End Class
我用下列的编程做的VB命令, 程序本身运行正常. 不过就是SQL里的更新password不能被更新.
奇怪的是当生成可执行文件.exe后, password又,没有问题. 只是在用F5调试的时候不行.Imports System.Data
Imports System.Data.SqlClientPublic 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)
End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Try
con = New SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\DatabaseStaff.mdf; Integrated Security=True") adap = New SqlDataAdapter("SELECT * FROM [Password] where Username='" & Trim(ComboBox1.Text) & "'and Pwd = '" & 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 pwd= '" & Trim(TextBox2.Text) & "' where Username = '" & Trim(ComboBox1.Text) & "'"
MsgBox(cmd.CommandText)
cmd.Connection = con
con.Open()
cmd.ExecuteNonQuery()
con.Close()
''???????????????
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
Catch ex As Exception
MessageBox.Show(ex.Message) End Try End Sub
End Class
LocalDB 的连接模式好像是独占的。
不好意思我是新手