Solved

.NET PROBLEM, UPDATE OF TABLE NOT HAPPENING

Posted on 2002-04-25
4
202 Views
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)

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


        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?




0
Comment
Question by:castello
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
smkkaleem earned 50 total points
Comment Utility
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

0
 

Author Comment

by:castello
Comment Utility
This is on Access
0
 
LVL 1

Expert Comment

by:Moondancer
Comment Utility
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.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
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.
http://www.experts-exchange.com/questions/Q.20288360.html
http://www.experts-exchange.com/questions/Q.20285461.html
http://www.experts-exchange.com/questions/Q.20285940.html
http://www.experts-exchange.com/questions/Q.20289881.html
http://www.experts-exchange.com/questions/Q.20293658.html
http://www.experts-exchange.com/questions/Q.20302062.html
http://www.experts-exchange.com/questions/Q.20302067.html
http://www.experts-exchange.com/questions/Q.20302069.html

To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://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
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://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
0
 
LVL 1

Expert Comment

by:Moondancer
Comment Utility
Thanks again, for returning and finalizing your open items.
:) Moondancer - EE Moderator
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now