...

View Full Version : asp.net update record problem



fazthegreat
01-30-2007, 02:37 AM
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

vinyl-junkie
01-30-2007, 04:24 AM
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:


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

fazthegreat
01-31-2007, 02:05 AM
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.

vinyl-junkie
01-31-2007, 02:45 AM
Are you sure you have that record in your database to update it in the first place?

fazthegreat
02-01-2007, 03:38 AM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum