Home > Software engineering >  Cannot update VB2013 database
Cannot update VB2013 database

Time:09-27

A great god, the question to me for a long time didn't wait for the answer.
I made of the following programming VB command, running to the program itself. But is in a SQL update password cannot be updated.
It is strange that when generating executable file. Exe, the password again, no problem. Just use F5 when debugging.

 Imports System. Data 
Imports System. The Data. SqlClient

Public Class Form2
Dim con As SqlConnection
Dim adap As SqlDataAdapter
Dim CMD As SqlCommand
Dim ds As the DataSet

Private Sub Form2_Load (sender As Object, As EventArgs e) Handles MyBase. Load
'TODO: This line of code loads data into the' DatabaseStaffDataSet. Password 'table. You can move, or remove it, as men.
Me. PasswordTableAdapter. The Fill Me. DatabaseStaffDataSet. (Password)


End Sub

Private Sub Button1_Click (sender As Object, As EventArgs e) Handles for. Click

Try
Con=New SqlConnection (" Data Source=(LocalDB) \ v11.0; AttachDbFilename=| DataDirectory | \ DatabaseStaff. MDF; Integrated Security=True ")



Adap=New SqlDataAdapter (" SELECT * FROM [Password] where the Username='" & amp; Trim (ComboBox1. Text) & amp; "' and Pwd=" & amp; Trim (TextBox1. Text) & amp; "';" , con)
Ds=New DataSet ()
Adap. The Fill (ds, "Password")
Dim count=ds. The Tables (" Password "). The Rows. Count

If the count & gt; 0 Then
If the Trim (TextBox2. Text)=Trim (TextBox3. Text) And Len (TextBox2. Text) & gt; 2 Then
CMD=New SqlCommand ()

Cmd.Com mandText="update Password set the PWD='" & amp; Trim (TextBox2. Text) & amp; "' the where the Username='" & amp; Trim (ComboBox1. Text) & amp; "'
"MsgBox mandText (cmd.Com)
CMD. Connection=con
Con. The Open ()
CMD. ExecuteNonQuery ()
Con. The Close ()


' '???????????????????????
MsgBox (" Dear "& amp; Trim (ComboBox1. Text) & amp; ", Your password has had changed ")

ElseIf Trim (TextBox2. Text) & lt;> Trim (TextBox3. Text) Then
MsgBox (" Your new passwords do not match ", MsgBoxStyle. Critical)
ElseIf Len (TextBox2. Text) & lt; 3 Then
MsgBox (" New password must be at further 3 charactors ", MsgBoxStyle. Critical)
End the If

The Else
MsgBox (" Current password Wrong, both please check your usename and password ", MsgBoxStyle. Critical)
End the If
Catch the ex As Exception
MessageBox. Show (ex. Message)

End the Try

End Sub
End the Class

CodePudding user response:

Is most likely your VS2013 have to connect the database,
Seems to be the exclusive LocalDB connection mode,

CodePudding user response:

reference 1st floor Tiger_Zhao response:
is most likely your VS2013 have to connect the database,
LocalDB connection mode is exclusive,
how to solve it, please?

CodePudding user response:

Close the connection in VS2003,
Check the server explorer, data sources,

CodePudding user response:

reference Tiger_Zhao reply: 3/f
VS2003 in close connection,
Check the server explorer, data sources,
with the connection. The close () doesn't work? Specific how to check? What to write statement to turn off?
Sorry I'm a beginner

CodePudding user response:

Like "walk don't trample shit",
A word is enough to will,
Write a paper for not all explanation is not clear,

CodePudding user response:

reference 5 floor Tiger_Zhao reply:
, like "walk don't trample shit",
A word is enough to will,
Write a paper for not all explanation is not clear,
  • Related