castello
asked on
.NET PROBLEM, UPDATE OF TABLE NOT HAPPENING
I am trying to update a row in a table used to track passwords & usernames. I'm getting no error and no rows updated.
The table is like this:
username varchar
pw varchar
restid smallint
I can "Log in" , select the right row from the table, using this code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cmd As System.Data.OleDb.OleDbCom mand = DBTheBusiness.CreateComman d
Dim cmdUpdate As System.Data.OleDb.OleDbCom mand = DBTheBusiness.CreateComman d
Dim nrows As Integer
cmd.CommandText = "select restid from uservalidate "
cmd.CommandText = cmd.CommandText & "where username = @username and "
cmd.CommandText = cmd.CommandText & "PW = @pw and "
cmd.CommandText = cmd.CommandText & "restid = @restid"
Dim adapt As New System.Data.OleDb.OleDbDat aAdapter(c md.Command Text, DBTheBusiness)
Dim username As System.Data.OleDb.OleDbPar ameter = cmd.Parameters.Add("@usern ame", SqlDbType.VarChar)
Dim pw As System.Data.OleDb.OleDbPar ameter = cmd.Parameters.Add("@pw", SqlDbType.VarChar)
Dim restid As System.Data.OleDb.OleDbPar ameter = cmd.Parameters.Add("@resti d", SqlDbType.Int)
username.Value = (txtUser.Text)
pw.Value = (TxtPW.Text)
restid.Value = CInt(txtRestId.Text)
DBTheBusiness.Open()
nrows = cmd.ExecuteScalar
lblhide.Text = CStr(nrows)
DBTheBusiness.Close()
If nrows = 0 Then
lblnotconnected.Text = "Invalid login. Correct and try again"
Exit Sub
End If
txtChgUN.Enabled = True
txtChgUN.BackColor = System.Drawing.Color.White
txtChgPW1.Enabled = True
txtChgPW1.BackColor = System.Drawing.Color.White
txtChgPW2.Enabled = True
txtChgPW2.BackColor = System.Drawing.Color.White
BtnChgPW.Enabled = True
End Sub
But I can't update using this:
Private Sub BtnChgPW_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnChgPW.Click
If Trim(txtChgUN.Text) = "" Then
lblnotconnected.Text = "User Name cannot be blank"
Exit Sub
End If
If Len(Trim(txtChgUN.Text)) < 8 Then
lblnotconnected.Text = "User name length must be between 8 & 15 Characters"
Exit Sub
End If
If Len(Trim(txtChgPW1.Text)) < 6 Then
lblnotconnected.Text = "Password length must be between 6 & 8 Characters"
Exit Sub
End If
If Trim(txtChgPW1.Text) <> Trim(txtChgPW2.Text) Then
lblnotconnected.Text = "Password & Confirmed Password are not the same. Please re-enter them"
Exit Sub
End If
lblnotconnected.Text = "Changing User Name & Password to " & txtChgPW2.Text
Dim cmd As System.Data.OleDb.OleDbCom mand = DBTheBusiness.CreateComman d
Dim username As System.Data.OleDb.OleDbPar ameter = cmd.Parameters.Add("@usern ame", SqlDbType.VarChar)
Dim pw As System.Data.OleDb.OleDbPar ameter = cmd.Parameters.Add("@pw", SqlDbType.VarChar)
Dim restid As System.Data.OleDb.OleDbPar ameter = cmd.Parameters.Add("@resti d", SqlDbType.Int)
pw.Value = txtChgPW1.Text
username.Value = txtChgUN.Text
restid.Value = CInt(lblhide.Text)
lblnotconnected.Text = CStr(restid.Value) & " " & username.Value & " " & pw.Value
DBTheBusiness.Open()
cmd.CommandText = "update uservalidate set username = @username, "
cmd.CommandText = cmd.CommandText & " pw = @pw "
cmd.CommandText = cmd.CommandText & " where username = @username"
cmd.CommandText = cmd.CommandText & " and pw = @pw "
cmd.CommandText = cmd.CommandText & " and restid = @restid ; "
lblnotconnected.Text = cmd.ExecuteNonQuery() & " Executed " & Chr(13) & CStr(restid.Value) & " " & username.Value & " " & pw.Value
DBTheBusiness.Close()
End Sub
lblconnected shows this:
0 Executed 1 john sayre asdfgh
Zero rows executed
restid (the paramater) = 1 - Correct
username (parameter) correct
pw (parameter) correct
What am I missing?
The table is like this:
username varchar
pw varchar
restid smallint
I can "Log in" , select the right row from the table, using this code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cmd As System.Data.OleDb.OleDbCom
Dim cmdUpdate As System.Data.OleDb.OleDbCom
Dim nrows As Integer
cmd.CommandText = "select restid from uservalidate "
cmd.CommandText = cmd.CommandText & "where username = @username and "
cmd.CommandText = cmd.CommandText & "PW = @pw and "
cmd.CommandText = cmd.CommandText & "restid = @restid"
Dim adapt As New System.Data.OleDb.OleDbDat
Dim username As System.Data.OleDb.OleDbPar
Dim pw As System.Data.OleDb.OleDbPar
Dim restid As System.Data.OleDb.OleDbPar
username.Value = (txtUser.Text)
pw.Value = (TxtPW.Text)
restid.Value = CInt(txtRestId.Text)
DBTheBusiness.Open()
nrows = cmd.ExecuteScalar
lblhide.Text = CStr(nrows)
DBTheBusiness.Close()
If nrows = 0 Then
lblnotconnected.Text = "Invalid login. Correct and try again"
Exit Sub
End If
txtChgUN.Enabled = True
txtChgUN.BackColor = System.Drawing.Color.White
txtChgPW1.Enabled = True
txtChgPW1.BackColor = System.Drawing.Color.White
txtChgPW2.Enabled = True
txtChgPW2.BackColor = System.Drawing.Color.White
BtnChgPW.Enabled = True
End Sub
But I can't update using this:
Private Sub BtnChgPW_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnChgPW.Click
If Trim(txtChgUN.Text) = "" Then
lblnotconnected.Text = "User Name cannot be blank"
Exit Sub
End If
If Len(Trim(txtChgUN.Text)) < 8 Then
lblnotconnected.Text = "User name length must be between 8 & 15 Characters"
Exit Sub
End If
If Len(Trim(txtChgPW1.Text)) < 6 Then
lblnotconnected.Text = "Password length must be between 6 & 8 Characters"
Exit Sub
End If
If Trim(txtChgPW1.Text) <> Trim(txtChgPW2.Text) Then
lblnotconnected.Text = "Password & Confirmed Password are not the same. Please re-enter them"
Exit Sub
End If
lblnotconnected.Text = "Changing User Name & Password to " & txtChgPW2.Text
Dim cmd As System.Data.OleDb.OleDbCom
Dim username As System.Data.OleDb.OleDbPar
Dim pw As System.Data.OleDb.OleDbPar
Dim restid As System.Data.OleDb.OleDbPar
pw.Value = txtChgPW1.Text
username.Value = txtChgUN.Text
restid.Value = CInt(lblhide.Text)
lblnotconnected.Text = CStr(restid.Value) & " " & username.Value & " " & pw.Value
DBTheBusiness.Open()
cmd.CommandText = "update uservalidate set username = @username, "
cmd.CommandText = cmd.CommandText & " pw = @pw "
cmd.CommandText = cmd.CommandText & " where username = @username"
cmd.CommandText = cmd.CommandText & " and pw = @pw "
cmd.CommandText = cmd.CommandText & " and restid = @restid ; "
lblnotconnected.Text = cmd.ExecuteNonQuery() & " Executed " & Chr(13) & CStr(restid.Value) & " " & username.Value & " " & pw.Value
DBTheBusiness.Close()
End Sub
lblconnected shows this:
0 Executed 1 john sayre asdfgh
Zero rows executed
restid (the paramater) = 1 - Correct
username (parameter) correct
pw (parameter) correct
What am I missing?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY. Moderators Computer101, Netminder or Mindphaser will return to finalize these if they are still open in 7 days. Experts, please post closing recommendations before that time.
Below are your open questions as of today. Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response. This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database. If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
--> Post comments for expert of your intention to delete and why
--> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.
For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process. https://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp
Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.
Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added. When you grade the question less than an A, please comment as to why. This helps all involved, as well as others who may access this item in the future. PLEASE DO NOT AWARD POINTS TO ME.
To view your open questions, please click the following link(s) and keep them all current with updates.
https://www.experts-exchange.com/questions/Q.20288360.html
https://www.experts-exchange.com/questions/Q.20285461.html
https://www.experts-exchange.com/questions/Q.20285940.html
https://www.experts-exchange.com/questions/Q.20289881.html
https://www.experts-exchange.com/questions/Q.20293658.html
https://www.experts-exchange.com/questions/Q.20302062.html
https://www.experts-exchange.com/questions/Q.20302067.html
https://www.experts-exchange.com/questions/Q.20302069.html
To view your locked questions, please click the following link(s) and evaluate the proposed answer.
https://www.experts-exchange.com/questions/Q.20302065.html
***** E X P E R T S P L E A S E ****** Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
POINTS FOR EXPERTS awaiting comments are listed in the link below
https://www.experts-exchange.com/commspt/Q.20277028.html
Moderators will finalize this question if in @7 days Asker has not responded. This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
Below are your open questions as of today. Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response. This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database. If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
--> Post comments for expert of your intention to delete and why
--> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.
For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process. https://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp
Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.
Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added. When you grade the question less than an A, please comment as to why. This helps all involved, as well as others who may access this item in the future. PLEASE DO NOT AWARD POINTS TO ME.
To view your open questions, please click the following link(s) and keep them all current with updates.
https://www.experts-exchange.com/questions/Q.20288360.html
https://www.experts-exchange.com/questions/Q.20285461.html
https://www.experts-exchange.com/questions/Q.20285940.html
https://www.experts-exchange.com/questions/Q.20289881.html
https://www.experts-exchange.com/questions/Q.20293658.html
https://www.experts-exchange.com/questions/Q.20302062.html
https://www.experts-exchange.com/questions/Q.20302067.html
https://www.experts-exchange.com/questions/Q.20302069.html
To view your locked questions, please click the following link(s) and evaluate the proposed answer.
https://www.experts-exchange.com/questions/Q.20302065.html
***** E X P E R T S P L E A S E ****** Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
POINTS FOR EXPERTS awaiting comments are listed in the link below
https://www.experts-exchange.com/commspt/Q.20277028.html
Moderators will finalize this question if in @7 days Asker has not responded. This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
Thanks again, for returning and finalizing your open items.
:) Moondancer - EE Moderator
:) Moondancer - EE Moderator
ASKER