After a several day break from programming (also known as "returning to sanity") I have reentered the world of ASP.NET programming (also known as "driving oneself insane"), and have written almost another entire file before running into an error I can't fix...
What I am trying to do is take an entry from a database, read it into a form, allow the user to edit the info., then update the database. The reading into works fine, the updating the edited data does not. Here is the code from my code-behind:
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Data
Imports System.Data.OleDb
Public Class EditEvent
Inherits Page
Protected lblID as Label
Protected txtMonth as TextBox
Protected txtDay as TextBox
Protected txtYear as TextBox
Protected txtEvent as TextBox
Protected withEvents cmdSubmit as Button
Private Sub Page_Load(Sender as Object, e as eventargs) Handles MyBase.Load
Dim con as New OleDBConnection()
con.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\ASP.NET\Databases\TodayInHistory\civilwar.mdb"
con.Open
Dim cmd as New OleDBCommand()
cmd.Connection=con
cmd.CommandText="Select * from tblToday WHERE ID=" & Request.QueryString("ID")
Dim reader as OleDBDataReader
reader = cmd.ExecuteReader()
reader.Read()
lblID.Text= reader("ID")
txtMonth.Text= reader("mMonth")
txtDay.Text=reader("mDay")
txtYear.Text=reader("mYear")
txtEvent.Text=reader("mEvent")
reader.Close()
con.Close()
End Sub
Private Sub ButtonClick(Sender as Object, e as EventArgs) Handles cmdSubmit.Click
Dim UpdateDB as String
UpdateDB="UPDATE tblToday SET"
UpdateDB &="ID='" & lblID.Text & "',"
UpdateDB &="mMonth='" & txtMonth.Text & "',"
UpdateDB &="mDay='" & txtDay.Text & "',"
UpdateDB &="mYear='" & txtYear.Text & "',"
UpdateDB &="mEvent='" & txtEvent.Text & "'"
UpdateDB &="WHERE ID='" & lblID.Text & "'"
Dim con as New OleDBConnection()
con.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\ASP.NET\Databases\TodayInHistory\civilwar.mdb"
con.Open()
Dim cmd as New OleDBCommand()
cmd.CommandText=UpdateDB
cmd.Connection=con
Dim Updated as Integer
Updated=cmd.ExecuteNonQuery
lblID.Text=Updated.ToString()
con.close()
End Sub
End Class
Here is the error:
System.Data.OleDb.OleDbException: Syntax error in UPDATE statement.
Here is the stack trace:
[OleDbException (0x80040e14): Syntax error in UPDATE
statement.]
System.Data.OleDb.OleDbCommand.ExecuteCommandText
ErrorHandling(Int32 hr) +41
System.Data.OleDb.OleDbCommand.ExecuteCommandText
ForSingleResult(tagDBPARAMS dbParams, Object& execute
Result) +122
System.Data.OleDb.OleDbCommand.ExecuteCommandText
(Object& executeResult) +92
System.Data.OleDb.OleDbCommand.ExecuteCommand
(CommandBehavior behavior, Object& executeResult) +65
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal
(CommandBehavior behavior, String method) +112
System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +66
EditEvent.ButtonClick(Object Sender, EventArgs e) +346
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
+83
System.Web.UI.WebControls.Button.System.Web.UI.
IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent
(IPostBackEventHandler sourceControl, String
eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent
(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277
Any ideas are appreciated.