I have an update statement that works only if I hard code in what I want. I want to use a variable, but I don't get an error, it just never works. I kid you not when I say that I've spent 5 hours on this. I've given up... please help!
This is the code for on page load -->
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("securelogin") <> True Then
Response.Redirect("loggedout.aspx")
Else
MultiView1.SetActiveView(View1)
strid = Request.QueryString("id")
strvl = Request.QueryString("vl")
Dim cmsData As New DataTable
Dim cmsCt As New SqlConnection(ConnectionString)
Dim cmsAdapt As New SqlDataAdapter
'Try
Dim cmsQuery As String = "SELECT * FROM tblPages WHERE ID = @ID AND VIEWER_LEVEL = @VIEWER_LEVEL "
cmsAdapt.SelectCommand = New SqlCommand(cmsQuery, cmsCt)
cmsAdapt.SelectCommand.Parameters.Add(New SqlParameter("@ID", strid))
cmsAdapt.SelectCommand.Parameters.Add(New SqlParameter("@VIEWER_LEVEl", strvl))
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)
strCont = Utils.CheckForNull_Text(dr.Item("PAGE_CONTENT"), "")
txtInfo.Text = strCont
strmessage = txtInfo.Text
Else
lblError.Text = "***Error. No page to update based on the QueryString. Please try again. <br/>"
End If
cmsData.Clear()
End If
End Sub
-------------------------------------------------------------------------------------------------
this is on the button click -->
Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
Response.Write(strmessage)
'the above line does work... it displays the message, but a few lines below... NOTHING.
strQuery = "Update tblPages set PAGE_CONTENT=@PAGE_CONTENT WHERE ID=@ID"
cmd = New SqlCommand(strQuery, Connection)
cmd.Parameters.Add(New SqlParameter("@PAGE_CONTENT", SqlDbType.Text)).Value = strmessage
'note - if I use the line below instead of the one above it will insert the word anything.
'cmd.Parameters.Add(New SqlParameter("@PAGE_CONTENT", SqlDbType.Text)).Value = "ANYTHING"
cmd.Parameters.Add(New SqlParameter("@ID", SqlDbType.Int)).Value = strid
Connection.Open()
cmd.ExecuteNonQuery()
Connection.Close()
MultiView1.SetActiveView(View2)
End Sub