Click here to Skip to main content
15,308,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is my code, I am missing something because. It button click event is not updating the table and not giving me an error.

VB.NET
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
       Dim ShoppingCart_ID As String

       ShoppingCart_ID = "123ABC"


       Dim Confirmation As SqlDataSource = New SqlDataSource

       Confirmation.ConnectionString = ConfigurationManager.ConnectionStrings("GARNETConnectionString").ToString()


       Dim AdvertisementID As Integer
       AdvertisementID = DirectCast(FormView1.FindControl("AdvertisementIDLabel"), Label).Text


       Confirmation.UpdateCommand = "UPDATE [Advertisement_TB] SET ([ShoppingCart_ID] = @ShoppingCart_ID) WHERE ([AdvertisementID] = @AdvertisementID)"

       Confirmation.UpdateParameters.Add("AdvertisementID", AdvertisementID)
       Confirmation.UpdateParameters.Add("ShoppingCart_ID", ShoppingCart_ID)

       '***

       'Label1.Text = ShoppingCart_ID - Tested that the data is passing but no update to the ShoppingCart_ID
       'Label2.Text = AdvertisementID - Tested that the data is passing
   End Sub


What I have tried:

Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim ShoppingCart_ID As String

ShoppingCart_ID = "123ABC"


Dim Confirmation As SqlDataSource = New SqlDataSource

Confirmation.ConnectionString = ConfigurationManager.ConnectionStrings("GARNETConnectionString").ToString()


Dim AdvertisementID As Integer
AdvertisementID = DirectCast(FormView1.FindControl("AdvertisementIDLabel"), Label).Text


Confirmation.UpdateCommand = "UPDATE [Advertisement_TB] SET (ShoppingCart_ID) VALUES (@ShoppingCart_ID) Where [AdvertisementID] = @AdvertisementID"

Confirmation.UpdateParameters.Add("AdvertisementID", AdvertisementID)
Confirmation.UpdateParameters.Add("ShoppingCart_ID", ShoppingCart_ID)

'***

'Label1.Text = ShoppingCart_ID - Tested that the data is passing but no update to the ShoppingCart_ID
'Label2.Text = AdvertisementID - Tested that the data is passing
End Sub
Posted
Updated 14-Mar-16 18:01pm

1 solution

I would have thought you'd need an Update() there somewhere - you've added the values for the parameters but havnt actually said 'do the update' .. maybe

Confirmation.UpdateParameters.Add("AdvertisementID", AdvertisementID)
Confirmation.UpdateParameters.Add("ShoppingCart_ID", ShoppingCart_ID)

Confirmation.Update();
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900