1loudsvt
04-05-2011, 09:48 PM
Been stuck on this for a while now, can create tables add to them, delete items from them but cannot get an update to stick to save my life. The code compiles and runs with no errors but the update never happens in the database. Here is my code in vb.net and i have tried numerous methods please let me know what i am missing thanks
the page loads text from a field in a table, allows the user to edit it then click an update button to write the changes back to the database.
Imports System.Data.OleDb
Partial Class CP
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Request.Cookies("LoggedIn") Is Nothing Then
pnlCP.Visible = False
lblError.Visible = True
ElseIf Request.Cookies("LoggedIn").Value = 0 Then
pnlCP.Visible = False
lblError.Visible = True
Else
pnlCP.Visible = True
lblError.Visible = False
End If
Dim strSQL2 As String
strSQL2 = "SELECT * from FrontPage WHERE Headline = 'a'"
Dim conConnection2 As New OleDbConnection
conConnection2.ConnectionString = "Provider=SQLOLEDB;Data Source=xxx;Initial Catalog=xxx;User ID=xxx;Password=xxx;"
conConnection2.Open()
Dim cmdcommand2 As New OleDbCommand(strSQL2, conConnection2)
Dim rdrReader2 As OleDbDataReader
rdrReader2 = cmdcommand2.ExecuteReader
If rdrReader2.Read Then
txtFP.Text = rdrReader2("body").ToString
End If
rdrReader2.Close()
cmdcommand2.Dispose()
conConnection2.Close()
End Sub
Protected Sub btnUpdt_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdt.Click
Dim strSQL As String
Dim strFP As String = txtFP.Text
strSQL = "UPDATE FrontPage SET body = '" + strFP + "' where Headline = 'a'"
Dim conConnection As New OleDbConnection
conConnection.ConnectionString = "Provider=SQLOLEDB;Data Source=xxx;Initial Catalog=xxx;User ID=xxx;Password=xxx;"
conConnection.Open()
Dim cmdCommand As New OleDbCommand(strSQL, conConnection)
cmdCommand.ExecuteNonQuery()
cmdCommand.Dispose()
conConnection.Close()
End Sub
the page loads text from a field in a table, allows the user to edit it then click an update button to write the changes back to the database.
Imports System.Data.OleDb
Partial Class CP
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Request.Cookies("LoggedIn") Is Nothing Then
pnlCP.Visible = False
lblError.Visible = True
ElseIf Request.Cookies("LoggedIn").Value = 0 Then
pnlCP.Visible = False
lblError.Visible = True
Else
pnlCP.Visible = True
lblError.Visible = False
End If
Dim strSQL2 As String
strSQL2 = "SELECT * from FrontPage WHERE Headline = 'a'"
Dim conConnection2 As New OleDbConnection
conConnection2.ConnectionString = "Provider=SQLOLEDB;Data Source=xxx;Initial Catalog=xxx;User ID=xxx;Password=xxx;"
conConnection2.Open()
Dim cmdcommand2 As New OleDbCommand(strSQL2, conConnection2)
Dim rdrReader2 As OleDbDataReader
rdrReader2 = cmdcommand2.ExecuteReader
If rdrReader2.Read Then
txtFP.Text = rdrReader2("body").ToString
End If
rdrReader2.Close()
cmdcommand2.Dispose()
conConnection2.Close()
End Sub
Protected Sub btnUpdt_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdt.Click
Dim strSQL As String
Dim strFP As String = txtFP.Text
strSQL = "UPDATE FrontPage SET body = '" + strFP + "' where Headline = 'a'"
Dim conConnection As New OleDbConnection
conConnection.ConnectionString = "Provider=SQLOLEDB;Data Source=xxx;Initial Catalog=xxx;User ID=xxx;Password=xxx;"
conConnection.Open()
Dim cmdCommand As New OleDbCommand(strSQL, conConnection)
cmdCommand.ExecuteNonQuery()
cmdCommand.Dispose()
conConnection.Close()
End Sub