大神好, 這個問題折磨我很久了還是沒有等到答案.
我用下列的編程做的VB命令, 程式本身運行正常. 不過就是SQL里的更新password不能被更新.
奇怪的是當生成可執行檔案.exe后, password又,沒有問題. 只是在用F5除錯的時候不行.

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)
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
uj5u.com熱心網友回復:
最大的可能是你的 VS2013 已經連接了這個資料庫。LocalDB 的連接模式好像是獨占的。
uj5u.com熱心網友回復:
請問怎么樣才能解決?uj5u.com熱心網友回復:
VS2003中關閉連接啊。檢查下服務器資源管理器、資料源。
uj5u.com熱心網友回復:
用connection.close()不行嘛? 具體怎么檢查?寫什么陳述句去關掉?不好意思我是新手
uj5u.com熱心網友回復:
就像“走路別踩狗屎”一樣,對會的人一句話就夠了,
對不會的人寫一篇論文都解釋不清楚。

uj5u.com熱心網友回復:


轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/84164.html
