Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    asp.net update record problem

    Hey guys, I'm having a problem updating a record.I'm using the code below:

    Sub UpdateMember(Sender as Object, e as EventArgs)

    cmd.CommandText="Update tbl_members Set title=@title Where member_id='" & intMemberId & "'"
    cmd.Parameters.Add("@title",txtTitle.Text)
    cmd.Connection = conn
    conn.open()
    cmd.ExecuteNonQuery()
    conn.close()
    response.Redirect("members_profile.aspx?view=")

    End Sub

    The above code works fine if I don't use parameter e.g if I use Set title='some text'

    Can someone please tell me what am I doing wrong.

    Thanks

  • #2
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,091
    Thanks
    2
    Thanked 23 Times in 23 Posts
    Your problem is most likely the quotes around the member id variable. When you have quotes around it, SQL treats it as if it's a text field. Do this instead:

    Code:
    cmd.CommandText="Update tbl_members Set title=@title Where member_id=" & intMemberId
    p.s. - You need to wrap your code in BB code tags. Makes it easier to disinguish code from the rest of your post.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #3
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh ok, thanks I'll do that next time.

    Yeah that was definitely one mistake but I still cannot get the record to update.Really don't know why.

  • #4
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,091
    Thanks
    2
    Thanked 23 Times in 23 Posts
    Are you sure you have that record in your database to update it in the first place?
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #5
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, the record is in there. I took a different route as follows:

    Dim cmd_builder as new sqlcommandbuilder(da)
    dim dr as datarow

    ds.tables(0).rows(0)("title")=txtTitle.text

    dim changed as new dataset
    changed=ds.getchanges()
    If Not changed is Nothing then
    conn.open()

    da.update(ds)
    ds.acceptchanges()
    conn.close()


    It works if I make:ds.tables(0).rows(0)("title")="Some Text"

    but does not work with the text box vlaue.It is so wiered.I've checked the text box name and properties n stuff.Everything seems fine.This thing is driving me crazy


  •  

    Posting Permissions

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