Results 1 to 6 of 6

Thread: Update statement not working?

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2003
    Posts
    58

    Update statement not working?

    I'm stuck with my update statement for a access2000 file.

    I have a table called email with 2 fields. (name and email)
    I can Add to it just fine, but I can't update.
    This is what I have

    in my access table I have

    Name Email
    perry [email protected]
    peter [email protected]



    value1 = "newname"
    Dim mycn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "C:/donation.mdb")

    Dim mycmd As OleDbCommand = New OleDbCommand
    mycmd.Connection = mycn
    mycmd.CommandText = "UPDATE email SET name=value1 WHERE name='perry' AND email='[email protected]')"
    mycn.Open()
    mycmd.ExecuteNonQuery()
    mycn.Close()

    it will fail on mycmd.ExecuteNonQuery()

    What am I doing wrong?

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Basic string concantenation

    VB Code:
    1. mycmd.CommandText = "UPDATE email SET name='" & value1 & "' WHERE name='perry' AND email='[email protected]')"
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2003
    Posts
    58
    changed it to

    mycmd.CommandText = "UPDATE email SET name='hello' WHERE name='perry' AND email='[email protected]'"

    and still not working.

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    what error?
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    Member
    Join Date
    Jul 2003
    Posts
    58
    Object reference not set to an instance of an object

    in this line

    mycon.UpdateCommand.CommandText = "UPDATE email SET name='hello' WHERE name='perry' AND email='[email protected]'"

  6. #6

    Thread Starter
    Member
    Join Date
    Jul 2003
    Posts
    58
    please forget my last comment.
    It's working now...
    forgot that "[email protected]" was not in the database. duh....

    Thanks so much for helping me out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width