Welcome to WebmasterWorld Guest from 34.228.115.216

Forum Moderators: ocean10000

Message Too Old, No Replies

sql update not working

     
8:23 pm on Jun 24, 2010 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 24, 2005
posts:429
votes: 0


I've been racking my head into the wall for 2+ hours trying to figure this out. The update statement does not work. The date.Now() works and anything I hard code in works, but FNAME and LNAME don't update. Anybody?


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load




strid = Request.QueryString("id")
MultiView1.SetActiveView(View1)

' Response.Write(strid)

Dim cmsData As New DataTable
Dim cmsCt As New SqlConnection(ConnectionString)
Dim cmsAdapt As New SqlDataAdapter

'Try
Dim cmsQuery As String = "SELECT * FROM tblBrokerRegistration WHERE ID = @ID "
cmsAdapt.SelectCommand = New SqlCommand(cmsQuery, cmsCt)
cmsAdapt.SelectCommand.Parameters.Add(New SqlParameter("@ID", strid))


cmsAdapt.Fill(cmsData)
cmsCt.Close()
' Catch ex As Exception
' lblErrors.Text = "Could not connect to CMSWebData"
'Exit Sub
' End Try



If cmsData.Rows.Count > 0 Then
Dim dr As DataRow = cmsData.Rows(0)
txtFname.Text = Utils.CheckForNull_Text(dr.Item("FNAME"), "")
txtLname.Text = Utils.CheckForNull_Text(dr.Item("LNAME"), "")
txtCompany.Text = Utils.CheckForNull_Text(dr.Item("COMPANY"), "")
txtAddress.Text = Utils.CheckForNull_Text(dr.Item("ADDRESS"), "")
txtCity.Text = Utils.CheckForNull_Text(dr.Item("CITY"), "")
ddlSTATE.Text = Utils.CheckForNull_Text(dr.Item("STATE"), "")
txtZip.Text = Utils.CheckForNull_Text(dr.Item("ZIP"), "")
txtPhone.Text = Utils.CheckForNull_Text(dr.Item("PHONE"), "")
txtFax.Text = Utils.CheckForNull_Text(dr.Item("FAX"), "")
txtRepName.Text = Utils.CheckForNull_Text(dr.Item("REP_NAME"), "")
'ddlMailingList.text = Utils.CheckForNull_Text(dr.Item("MAILING_LIST"), "")
txtemailaddress.Text = Utils.CheckForNull_Text(dr.Item("EMAIL_ADDRESS"), "")
txtusername.Text = Utils.CheckForNull_Text(dr.Item("USERNAME"), "")
txtpassword.Text = Utils.CheckForNull_Text(dr.Item("PASSWORD"), "")
'txtactive.text = Utils.CheckForNull_Text(dr.Item("ACTIVE"), "")
'strrole.text = Utils.CheckForNull_Text(dr.Item("ROLE_LEVEL"), "")


Else




End If

cmsData.Clear()











'Response.Write(strid)
'Response.Write(strFname)
'Response.Write(strLname)





End Sub

Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click






strQuery = "Update tblBrokerRegistration set FNAME=@FNAME, LNAME=@LNAME, LAST_UPDATED=@LAST_UPDATED WHERE ID=@ID"

cmd = New SqlCommand(strQuery, Connection)


cmd.Parameters.Add(New SqlParameter("@ID", SqlDbType.Int)).Value = strid
cmd.Parameters.Add(New SqlParameter("@LAST_UPDATED", SqlDbType.DateTime)).Value = Date.Now()
cmd.Parameters.Add(New SqlParameter("@FNAME", SqlDbType.NVarChar, 50)).Value = strfname1
cmd.Parameters.Add(New SqlParameter("@LNAME", SqlDbType.NVarChar, 50)).Value = txtLname.Text


Connection.Open()
cmd.ExecuteNonQuery()
Connection.Close()

MultiView1.SetActiveView(View2)



lblComplete.Text = "The information has been saved!"
Response.Write(strid)
'Response.Write(strFname)
'Response.Write(strLname)





End Sub
8:25 pm on June 24, 2010 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 24, 2005
posts:429
votes: 0


p.s. this

cmd.Parameters.Add(New SqlParameter("@FNAME", SqlDbType.NVarChar, 50)).Value = strfname1
cmd.Parameters.Add(New SqlParameter("@LNAME", SqlDbType.NVarChar, 50)).Value = txtLname.Text

I guess should be

cmd.Parameters.Add(New SqlParameter("@FNAME", SqlDbType.NVarChar, 50)).Value = txtfname.Text
cmd.Parameters.Add(New SqlParameter("@LNAME", SqlDbType.NVarChar, 50)).Value = txtLname.Text

I've changed things many times... no luck.
it just uses the original info from the page load.
8:59 pm on June 24, 2010 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 24, 2005
posts:429
votes: 0


I figured it out...

I needed --> If Not Page.IsPostBack Then

! Time to go home!
6:46 am on June 25, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:732
votes: 0


I needed --> If Not Page.IsPostBack Then

! Time to go home!

When I was first starting with ASP.Net I made that same mistake *every* time... Now I always add the PostBack check first thing on a new page, whether I need it or not :)
12:21 pm on June 25, 2010 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 24, 2005
posts:429
votes: 0


I doubt I'll make that mistake again. I had a similar issue a few weeks ago. I should have learned then!
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members