Repost with code : Can't update an Access record.

M

Mark

Hi, I'm have problems updating records in an access db. I'm using the code
generated by WeB Matrix wizard for 'update'. The insert code and delete
code
work fine.
No eorror messages, it just won't update the rexord.
Where do I start looking?
I'm running the latest version of the DotNete framework onn a Win2k server
with IIS 5.0.



Update function code:


Function UpdateEventInfo(ByVal eventName As String, ByVal description As
String) As Integer
Dim connectionString As String =
ConfigurationSettings.AppSettings("constring_db")
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString)

Dim queryString As String = "UPDATE [Events] SET
[Description]=@Description WHERE ([Events].[EventName] = @Eve"& _
"ntName)"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_eventName As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_eventName.ParameterName = "@EventName"
dbParam_eventName.Value = eventName
dbParam_eventName.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_eventName)
Dim dbParam_description As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_description.ParameterName = "@Description"
dbParam_description.Value = description
dbParam_description.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_description)

Dim rowsAffected As Integer = 0
dbConnection.Open
'Try
rowsAffected = dbCommand.ExecuteNonQuery
'Finally
dbConnection.Close
'End Try

Return rowsAffected
End Function


-------------------------------------------------

Commit Button code:

Sub butUpdate_Click(sender As Object, e As EventArgs)
If IsValid Then

Dim intEventID, intRowsUpdated, intRowsDeleted As Integer
Dim strEventName As String
Dim strStartTime, strEndTime, strEventTime As String
Dim dtStartDate, dtEndDate As DateTime
Dim strLocation, strDescription, strReservations, strFireworks As
String
Dim strCost AS String
Dim strURL, strPubEmail, strSponsor, strContactName,
strContactPhone, strPhoneExt, strNotes As String

intEventID = Session("id")
strEventName = txtEventName.Text
strLocation = txtLocation.text
strDescription = txtDescription.Text
strURL = txtURL.Text
strPubEmail = txtEmail.Text
strSponsor = txtSponsor.Text
strContactName = txtContactName.Text
strNotes = txtNotes.Text
strCost = txtCost.Text

strStartTime = dropStart.SelectedItem.Value & " " &
radioStart.SelectedItem.Value
strEndTime = dropEnd.SelectedItem.Value & " " &
radioEnd.SelectedItem.Value
strEventTime = strStartTime & " - " & strEndTime
strReservations = radioReservations.SelectedItem.Value
strFireworks = radioFireworks.SelectedItem.Value
strContactPhone = txtContactPhone.Text
strPhoneExt = txtPhoneExt.Text

Try
dtStartDate = Convert.ToDateTime(txtStartDate.Text)
dtEndDate = Convert.ToDateTime(txtEndDate.Text)

Catch
Response.Redirect("error.aspx?Error=1")
End Try


'intRowsUpdated =
UpdateEventInfo(intEventID,strEventName,dtStartDate,dtEndDate,strEventTime,s
trLocation,strDescription,strCost,strReservations,strFireworks,strURL,strPub
Email,strSponsor,strContactName,strContactPhone,strPhoneExt,strNotes)
intRowsUpdated = UpdateEventInfo(strEventName,strDescription)
If intRowsUpdated = 1 Then
Response.Redirect("complete.aspx?Action=2")
Else
Response.Redirect("error.aspx?Error=3&ID=" & intEventID & "")
End If

End If


End Sub
__________________________________________


The aforementioned code send me to the error page call if intRowsUpdated is
0, meaning the data is not updating. And if I open the DB in Access, I can
see that it's not gettting there either.

TIA,

Mark
 
M

Mark

A little more info:
If I test the query using the wizard in WebMatrix, it tfinds the record.
The wizard won't let me try and change the data , though.

Mark said:
Hi, I'm have problems updating records in an access db. I'm using the code
generated by WeB Matrix wizard for 'update'. The insert code and delete
code
work fine.
No eorror messages, it just won't update the rexord.
Where do I start looking?
I'm running the latest version of the DotNete framework onn a Win2k server
with IIS 5.0.



Update function code:


Function UpdateEventInfo(ByVal eventName As String, ByVal description As
String) As Integer
Dim connectionString As String =
ConfigurationSettings.AppSettings("constring_db")
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString)

Dim queryString As String = "UPDATE [Events] SET
[Description]=@Description WHERE ([Events].[EventName] = @Eve"& _
"ntName)"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_eventName As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_eventName.ParameterName = "@EventName"
dbParam_eventName.Value = eventName
dbParam_eventName.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_eventName)
Dim dbParam_description As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_description.ParameterName = "@Description"
dbParam_description.Value = description
dbParam_description.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_description)

Dim rowsAffected As Integer = 0
dbConnection.Open
'Try
rowsAffected = dbCommand.ExecuteNonQuery
'Finally
dbConnection.Close
'End Try

Return rowsAffected
End Function


-------------------------------------------------

Commit Button code:

Sub butUpdate_Click(sender As Object, e As EventArgs)
If IsValid Then

Dim intEventID, intRowsUpdated, intRowsDeleted As Integer
Dim strEventName As String
Dim strStartTime, strEndTime, strEventTime As String
Dim dtStartDate, dtEndDate As DateTime
Dim strLocation, strDescription, strReservations, strFireworks As
String
Dim strCost AS String
Dim strURL, strPubEmail, strSponsor, strContactName,
strContactPhone, strPhoneExt, strNotes As String

intEventID = Session("id")
strEventName = txtEventName.Text
strLocation = txtLocation.text
strDescription = txtDescription.Text
strURL = txtURL.Text
strPubEmail = txtEmail.Text
strSponsor = txtSponsor.Text
strContactName = txtContactName.Text
strNotes = txtNotes.Text
strCost = txtCost.Text

strStartTime = dropStart.SelectedItem.Value & " " &
radioStart.SelectedItem.Value
strEndTime = dropEnd.SelectedItem.Value & " " &
radioEnd.SelectedItem.Value
strEventTime = strStartTime & " - " & strEndTime
strReservations = radioReservations.SelectedItem.Value
strFireworks = radioFireworks.SelectedItem.Value
strContactPhone = txtContactPhone.Text
strPhoneExt = txtPhoneExt.Text

Try
dtStartDate = Convert.ToDateTime(txtStartDate.Text)
dtEndDate = Convert.ToDateTime(txtEndDate.Text)

Catch
Response.Redirect("error.aspx?Error=1")
End Try


'intRowsUpdated =
UpdateEventInfo(intEventID,strEventName,dtStartDate,dtEndDate,strEventTime,strLocation,strDescription,strCost,strReservations,strFireworks,strURL,strPub
Email,strSponsor,strContactName,strContactPhone,strPhoneExt,strNotes)
intRowsUpdated = UpdateEventInfo(strEventName,strDescription)
If intRowsUpdated = 1 Then
Response.Redirect("complete.aspx?Action=2")
Else
Response.Redirect("error.aspx?Error=3&ID=" & intEventID & "")
End If

End If


End Sub
__________________________________________


The aforementioned code send me to the error page call if intRowsUpdated is
0, meaning the data is not updating. And if I open the DB in Access, I can
see that it's not gettting there either.

TIA,

Mark
 
Top