Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

.NET PROBLEM, UPDATE OF TABLE NOT HAPPENING

Posted on 2002-04-25
4
Medium Priority
?
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
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

0
 

Author Comment

by:castello
ID: 6970403
This is on Access
0
 
LVL 1

Expert Comment

by:Moondancer
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.
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
ID: 7024613
Thanks again, for returning and finalizing your open items.
:) Moondancer - EE Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

719 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