Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8834499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:02:05+00:00 2026-06-14T09:02:05+00:00

We would like to update data in a SQL Server 2012 database with a

  • 0

We would like to update data in a SQL Server 2012 database with a value obtained from
changing a value on an ASP.Net DetailsView. I Would would like to update the database using

  • a strongly typed DataSet called DataSetParentsDetails
  • a TableAdapter called ParentsDetailsTableAdapter
  • a DataTable called ParentsDetails.

These were created with the DataSet Designer.

This is the code from the code-behind file used to figure out the amount we want to update into the database:

Protected Sub DetailsViewDetails_ItemCommand(sender As Object, e As System.Web.UI.WebControls.DetailsViewCommandEventArgs)
  Dim dcmAmountToAdjust As Decimal
  Dim StrSqlStatement As String

  Select Case e.CommandName
    Case "Add"
    Case "Edit"
      dcmOriginalRegistrationFee = GetValueFromLabelRegistrationFee()
    Case "Delete"
    Case "Update"
      dcmNewRegistrationFee = GetValueFromTextBoxRegistrationFee()
      dcmAmountToAdjust = dcmNewRegistrationFee - dcmOriginalRegistrationFee
      ' Update the tuition balance in the parent's data.
      '-------------------------------------------------
      StrSqlStatement =
        "Update Students " & _
        "Set RegistrationCode = RegistrationCode + @AmountToAdjust " & _
        "Where StudentID = @ID"
      ' Code to update the database goes here.
      '---------------------------------------
  End Select
End Sub

I’m sure that this was asked many times before but I can’t find a good example on how to use the query in: StrSqlStatement to update the database through the strongly typed DataSet.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:02:06+00:00Added an answer on June 14, 2026 at 9:02 am

    First off you need a connection string, it’s good practise to store your connection strings in the web.config file:

    <connectionStrings>
      <add name="MyConnectionString" connectionString="Data Source=putYourServerAndInstanceNameHere;Initial Catalog=putYourDatabaseNameHere;User ID=putYourSqlUsernameHere;Password=password" providerName="System.Data.SqlClient" />
    </connectionStrings>
    

    This is a direct child of the root <configuration> element. For more information about connection strings, visit http://www.connectionstrings.com.

    Then you’ll need some imports in your code-behind, and you’ll need to add them as references to your project if you haven’t already got them in there:

    Import System.Data
    Import System.Data.SqlClient
    

    Then we connect to the database and run our command, we use parameters because they’re more secure.

    'build the connection object using the string from the web.config file
    Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString)
      'build the command object specifying the command text and the connection to use, conn
      Using cmd As New SqlCommand("UPDATE Students SET RegistrationCode = RegistrationCode + @AmountToAdjust WHERE StudentID = @ID", conn)
        'add the parameters needed by the command
        cmd.Parameters.AddWithValue("@AmountToAdjust", amountToAdjust)
        cmd.Parameters.AddWithValue("@ID", studentID)
        'try to open the connection and execute the statement
        Try
          conn.Open()
          cmd.ExecuteNonQuery()
        Catch ex As Exception
          'handle the exception here
        End Try
      End Using
    End Using
    

    Note that there is no need to use conn.Close() here as the Using statement will take care of that for you (SqlConnection’s Dispose method closes the connection if it is still open).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an asp.net web app which holds its data in an sql server
I would like to update some data with JSON when the user clicks on
I would like to know how to safely update data when programming with Entity
I would like to update an xml file from another xml file.I have used
I would like to update a number without changing its placement in the output
We are building an ASP.Net MVC 2 multi-tenant application on SQL Server using the
In SQL Server 2008, I would like to examine what is really going on
I have a server with a SQL Server 2012 Express database. I am authenticated
I would like to start with integration testing. I am using an ASP.NET MVC
I need to save measures coming from devices into a SQL database (SQL Server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.