I'm trying to update a database with a button_click event, but I just can't seem to get it to work. I tried following the example the way the microsoft website did it, but it will not update the databse :/ I've been at this for days and I can't seem to figure
it out. I don't get any errors, it just does NOT update the data. Any help would be awesome! This is for a school project, and my teacher couldn't help me figure it out.
Partial Class Final_Fantasy_XI_Default
Inherits System.Web.UI.Page
Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
sqlTextUpdate.Update()
End Sub
Sub On_Sql_Updating(ByVal source As Object, ByVal e As SqlDataSourceCommandEventArgs)
Dim command As DbCommand
Dim connection As DbConnection
Dim transaction As DbTransaction
I notice that you've defined all of your parameters for updating, and you don't need to handle the event of Updating or Updated. Please just try this by removing the two events below:
Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click sqlTextUpdate.Update()
End Sub
Sub On_Sql_Updating(ByVal source As Object, ByVal e As SqlDataSourceCommandEventArgs) Dim command As DbCommand Dim connection As DbConnection Dim transaction As DbTransaction
I tried just using the one in the button event, but that didn't work. It exewcutes with no errors but doesn't update the database. I can't seem to figure it out :/ Maybe my asp code is wrong?
I can't seem to figure it out :/ Maybe my asp code is wrong?
Hi,
The syntax of the SQL update isn't wrong. And I hope you can check your value to see whether your update statement can really upgrate your table or not.
Sonicrich05
0 Points
5 Posts
Problems with updating database with a button event
Nov 16, 2012 04:23 AM|LINK
Hello,
I'm trying to update a database with a button_click event, but I just can't seem to get it to work. I tried following the example the way the microsoft website did it, but it will not update the databse :/ I've been at this for days and I can't seem to figure it out. I don't get any errors, it just does NOT update the data. Any help would be awesome! This is for a school project, and my teacher couldn't help me figure it out.
My code is the following:
<asp:SqlDataSource ID="sqlTextUpdate" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
UpdateCommand="UPDATE sealData SET Seals_Aquired = @Seals_Aquired WHERE (characterID = @characterID) AND (sealID = @sealID)"
SelectCommand="SELECT [characterID], [sealID], [Seals_Aquired] FROM [sealData]">
<UpdateParameters>
<asp:ControlParameter ControlID="txtSealUpdate" Name="Seals_Aquired"
PropertyName="Text" />
<asp:ControlParameter ControlID="ddlNames" Name="characterID"
PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="ddlSeals" Name="sealID"
PropertyName="SelectedValue" />
</UpdateParameters>
</asp:SqlDataSource>
and in the code page I have
Option Explicit On
Option Strict On
Imports System.Data.Common
Partial Class Final_Fantasy_XI_Default
Inherits System.Web.UI.Page
Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
sqlTextUpdate.Update()
End Sub
Sub On_Sql_Updating(ByVal source As Object, ByVal e As SqlDataSourceCommandEventArgs)
Dim command As DbCommand
Dim connection As DbConnection
Dim transaction As DbTransaction
command = e.Command
connection = command.Connection
connection.Open()
transaction = connection.BeginTransaction()
command.Transaction = transaction
End Sub 'On_Sql_Updating
Sub On_Sql_Updated(ByVal source As Object, ByVal e As SqlDataSourceStatusEventArgs)
Dim command As DbCommand
Dim transaction As DbTransaction
command = e.Command
transaction = command.Transaction
Dim OtherProcessSucceeded As Boolean = True
If (OtherProcessSucceeded) Then
transaction.Commit()
Label1.Text = "The record was updated successfully!"
Else
transaction.Rollback()
End If
End Sub ' On_Sql_Updated
End Class
Sonicrich05
0 Points
5 Posts
Re: Problems with updating database with a button event
Nov 16, 2012 11:13 PM|LINK
Is there anyone who could help me out? I'd really appreciate it!
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Problems with updating database with a button event
Nov 17, 2012 12:17 AM|LINK
Hi,
I notice that you've defined all of your parameters for updating, and you don't need to handle the event of Updating or Updated. Please just try this by removing the two events below:
Sonicrich05
0 Points
5 Posts
Re: Problems with updating database with a button event
Nov 17, 2012 12:33 AM|LINK
Hello!
I tried just using the one in the button event, but that didn't work. It exewcutes with no errors but doesn't update the database. I can't seem to figure it out :/ Maybe my asp code is wrong?
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Problems with updating database with a button event
Nov 17, 2012 08:06 AM|LINK
Hi,
The syntax of the SQL update isn't wrong. And I hope you can check your value to see whether your update statement can really upgrate your table or not.
Reguards!