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 3618168
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:43:03+00:00 2026-05-18T22:43:03+00:00

i have in asp.net a few textboxes and i wish to update my database

  • 0

i have in asp.net a few textboxes and i wish to update my database with the values that they encapsulate .

The problem is that it doesn’t work and although it doesn’t work, the syntax seems correct and there are no errors present . Here is my linkbutton :

<asp:linkbutton id="clickOnSave" runat="server" 
                onclick="Save_Click" Text="Save Profile" />

and my update function

protected void Save_Click(object sender, EventArgs e)
{
    SqlConnection con = new System.Data.SqlClient.SqlConnection();
    con.ConnectionString = "DataSource=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\alex\\Documents\\seeubook_db.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";

    con.Open();

    String commandString = "UPDATE users SET last_name='" + Text4.Text.Trim() + "' , first_name='" + Textbox1.Text.Trim() + "' , about_me='" + Textbox5.Text.Trim() + "' , where_i_live='" +  Textbox2.Text.Trim() + "' ,  where_i_was_born='" + Textbox3.Text.Trim() + "' , work_place='" + Textbox4.Text.Trim() + "' WHERE email='" + Session["user"] + "'";

    SqlCommand sqlCmd = new SqlCommand(commandString, con);
    sqlCmd.ExecuteNonQuery();
    con.Close();
}
  • 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-18T22:43:03+00:00Added an answer on May 18, 2026 at 10:43 pm

    I’m always a bit weary about the User Instance=true in a connection string….. at times, it tends to create a new MDF file “on the fly” and when you update that MDF, then your changes might be just “gone” one your app has completed running…. See MSDN docs on User Instances.

    I would suggest that you:

    • attach your MDF file to SQL Server Express on your machine, using SQL Server Express Management Studio
    • then use a server-based approach to your SQL Server Express database rather than attaching a file…

    In that case, your database connection string would then look something like:

    server=.\\SQLEXPRESS;database=YourDatabaseName;Integrated Security=SSPI;
    

    And while you’re at it, I would also recommend to:

    • wrap your SqlConnection and SqlCommand into using blocks to ensure proper disposal
    • open your connection as late as possible
    • use a parametrized query instead of concatenating together your SQL command – doing so is a wide open door for SQL injection attacks!

    So your code would look something like this:

    string connStr = "server=.\\SQLEXPRESS;database=YourDatabaseName;Integrated Security=SSPI;";
    
    string cmdStmt = "UPDATE dbo.Users SET last_name = @lastName, " + 
       "first_name = @firstName, about_me = @aboutMe, where_i_live = @whereILive, " +  
       "where_i_was_born = @whereIWasBorn, work_place = @workPlace " +
       "WHERE email = @userEMail";
    
    using(SqlConnection sqlCon = new SqlConnection(connStr))
    using(SqlCommand sqlCmd = new SqlCommand(cmdStmt, sqlCon))
    {
       // define parameters 
       sqlCmd.Parameters.Add("@lastName", SqlDbType.VarChar, 50);
       sqlCmd.Parameters["@lastName"].Value = Text4.Text.Trim();
       // and so on for all the parameters
    
       sqlCon.Open();
       sqlCmd.ExecuteNonQuery();
       sqlCon.Close();
    }
    
    • 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 3.5 update panel and I have a few textboxes that
I have a few ASP.Net database front-end websites where MS Access is the back-end.
I have an asp.net website that uses forms authentication. There are a few things
I have a few controls that inherit from ASP.NET buttons and use onserverclick .
I have a few pages on my asp.net website that I would like to
I have an ASP.NET 4 webpage that contains an update panel which just allows
I have an asp.net page with a datalist with few textboxes, and a submit
I have an asp.net website which contains a few pages that I'd like to
I have an ASP.NET site that uses themes to implement a few variations. I
Have an ASP.net web app which works fine for a few days, but then

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.