Quantcast
Channel: Visual Studio and Visual Web Developer Express
Viewing all articles
Browse latest Browse all 3509

SQL Update on Button Click in Webpage

$
0
0

I am using VWD 2010 and SQL Server 2008.

I am trying to setup a button click event that will process an update command to my sql database.

I believe I am having trouble properly setting up the new sqldatasource and connectionstring in the button click event.

I know that this is how I would set it up with asp. I've been using this type of setup with no problems.

<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"

SelectCommand="SELECT [ProgramNumber], [ProgramName] FROM [Programs] WHERE ([ProgramNumber] = @ProgramNumber)">
<SelectParameters>
<asp:Parameter DefaultValue="300" Name="ProgramNumber" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>

Inside my button click event I tried:

Dim userprogramdatasource As New SqlDataSource()
userprogramdatasource.ConnectionString = ConfigurationManager.ConnectionStrings("MyConnectionString").ToString()

userprogramdatasource.UpdateCommandType = SqlDataSourceCommandType.Text
userprogramdatasource.UpdateCommand = "UPDATE User_Profile SET (ProgramNumber = @ProgramNumber) WHERE (UserName = @UserName)"

userprogramdatasource.InsertParameters.Add("ProgramNumber", DropDownList1.SelectedValue)
userprogramdatasource.InsertParameters.Add("UserName", User.Identity.Name.ToString())

When I test this, nothing happens. I have a URL redirect that is working, but no updates to the database.

Can anyone help me out?


Viewing all articles
Browse latest Browse all 3509

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>