Go Premium for a chance to win a PS4. Enter to Win



Posted on 2002-04-25
Medium Priority
Last Modified: 2012-05-04
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.OleDbCommand = DBTheBusiness.CreateCommand
        Dim cmdUpdate As System.Data.OleDb.OleDbCommand = DBTheBusiness.CreateCommand

        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.OleDbDataAdapter(cmd.CommandText, DBTheBusiness)
        Dim username As System.Data.OleDb.OleDbParameter = cmd.Parameters.Add("@username", SqlDbType.VarChar)
        Dim pw As System.Data.OleDb.OleDbParameter = cmd.Parameters.Add("@pw", SqlDbType.VarChar)
        Dim restid As System.Data.OleDb.OleDbParameter = cmd.Parameters.Add("@restid", SqlDbType.Int)

        username.Value = (txtUser.Text)
        pw.Value = (TxtPW.Text)
        restid.Value = CInt(txtRestId.Text)

        nrows = cmd.ExecuteScalar
        lblhide.Text = CStr(nrows)
        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.OleDbCommand = DBTheBusiness.CreateCommand

        Dim username As System.Data.OleDb.OleDbParameter = cmd.Parameters.Add("@username", SqlDbType.VarChar)
        Dim pw As System.Data.OleDb.OleDbParameter = cmd.Parameters.Add("@pw", SqlDbType.VarChar)
        Dim restid As System.Data.OleDb.OleDbParameter = cmd.Parameters.Add("@restid", SqlDbType.Int)

        pw.Value = txtChgPW1.Text
        username.Value = txtChgUN.Text
        restid.Value = CInt(lblhide.Text)

        lblnotconnected.Text = CStr(restid.Value) & " " & username.Value & " " & pw.Value

        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
    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?

Question by:castello
  • 2

Accepted Solution

smkkaleem earned 200 total points
ID: 6970137
I can not see the following line in the code:

cmd.CommandType = CommandType.Text

also, are u using SQL Server database, if yes then why not use SqlClient e.g
Dim dbConn As SqlClient.SqlConnection
Dim cmdColumn As SqlClient.SqlCommand

and then use a stored procedure to execute i.e

Dim cmd As New SqlClient.SqlCommand("dbo.spbillSupp_Insert_BillHdr", dbConn)

'Set up a command object. (Assumes that the database 'contains a stored procedure 'called "spbillSupp_Select_BillHdr_CycleCount".)
            cmd.CommandType = CommandType.StoredProcedure


Author Comment

ID: 6970403
This is on Access

Expert Comment

ID: 7018948
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.
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://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.

To view your locked questions, please click the following link(s) and evaluate the proposed answer.

*****  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
POINTS FOR EXPERTS awaiting comments are listed in the link below
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.
Moderator @ Experts Exchange

Expert Comment

ID: 7024613
Thanks again, for returning and finalizing your open items.
:) Moondancer - EE Moderator

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question