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

  • Home
  • SEARCH
  • 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 709903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:33:19+00:00 2026-05-14T04:33:19+00:00

I have a web application and on page is an update page to update

  • 0

I have a web application and on page is an update page to update some profile information. Below is the code I am using to update the table. But I think it is wrong. Does anything stick out? The connection string works cause it is used to read the database to get the profile information, I just removed it due to it containing password/login info for the db.

player is the class of properties that contains player information and ds is the dataset, but I would like to update the database itself online…

 Dim connectionString As String = ""

 Dim GigsterDBConnection As New System.Data.SqlClient.SqlConnection(connectionString)
 GigsterDBConnection.Open()
 Dim updatetoursql As String = "UPDATE PLAYERS SET FIRSTNAME = '" & player.FIRSTNAME & "', LASTNAME =  '" & player.LASTNAME & "', ADDRESS = '" & player.ADDRESS & "', CITY =  '" & player.CITY & "', ZIP = '" & player.ZIP & "', PHONE =  '" & player.PHONE & "', EMAIL = '" & player.EMAIL & "', REFFEREDBY =  '" & player.REFEREDBY & "' "

 updatetoursql = updatetoursql & "PLAYERID = '" & player.PLAYERID & "';"

 Dim cmd As New System.Data.SqlClient.SqlCommand(updatetoursql, GigsterDBConnection)
 Dim sqlAdapter As New System.Data.SqlClient.SqlDataAdapter(cmd)
 sqlAdapter.Update(ds, "PLAYERS")

I think the issue is something the 3 last lines of the code. am I doing it right or is their a better way?

Thanks

  • 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-05-14T04:33:20+00:00Added an answer on May 14, 2026 at 4:33 am

    Well, apart from the glaring SQL injection issues waiting to bite you ….. (hint: use parametrized queries instead of concatenating together your SQL statement!!)

    Dim cmd As New SqlCommand(updatetoursql, GigsterDBConnection)
    Dim sqlAdapter As New SqlDataAdapter(cmd)
    

    The problem here is: if you call the SqlDataAdapter constructor this way, what you’re passing in is the select command (of the data adapter) – not the update command!

    You need to do it this way:

    Dim cmd As New SqlCommand(updatetoursql, GigsterDBConnection)
    Dim sqlAdapter As New SqlDataAdapter()
    sqlAdapter.UpdateCommand = cmd;
    

    Now you’ve associated your UPDATE statement with the SqlDataAdapter.UpdateCommand and now it should work.

    About the SQL injection: I’d strongly recommend using parametrized queries all the time – at least in production code. So instead of concatenating together your query, use this:

    Dim updatetoursql As String = 
       "UPDATE PLAYERS SET FIRSTNAME = @FirstName, LASTNAME = @LastName, " & 
       "ADDRESS = @Address, CITY = @City, ZIP = @Zip, PHONE = @Phone " &
       "EMAIL = @EMail, REFFEREDBY = @ReferredBy, PLAYERID = @PlayerID"
    

    and then before you execute the command or the SqlDataAdapter.Update statement, set those parameters to the values you have. This is much safer and gives you less headaches and possibly even speed improvements (if that single Update query is only cached once in SQL Server memory).

    Also, why go the long and complicated way of a SqlDataAdapter at all??

    After you’ve created the SqlCommand and set all the parameters, just call cmd.ExecuteNonQuery(); and you’re done!

    Dim cmd As New SqlCommand(updatetoursql, GigsterDBConnection)
    
    // set up the parameters here.....
    cmd.Parameters.AddWithvalue("@FirstName", FirstName);
    ... etc.
    
    // just call ExecuteNonQuery - and you're done!
    cmd.ExecuteNonQuery();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a Web application (ASP.NET) which displays in some page links to miscellaneous
I have this web application using Spring Web Flow framework. In my main page
I have an application web.xml with the following entry: <error-page> <error-code>404</error-code> <location>/system_files/error/p_notfound.jsp</location> </error-page> However,
I have a web application that has a page that loads the content from
I have a web page that links to another web application, which unfortunately only
Hi i have a web application where i plant a cookie on my page.
I have a one page web application, which means alot of javascript. External scripts
I have made a web application that uses master page for Login & Logout
I have a page in my vb.net web application that needs to toss a
We have a web application running in a production enviroment and at some point

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.