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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:02:54+00:00 2026-06-04T12:02:54+00:00

I have written the following function meant to update a student in my database:

  • 0

I have written the following function meant to update a student in my database:

public bool UpdateStudent(Student stu)
{
   Console.WriteLine("StudentManger.UpdateStudent): Called");

   int rowsChanged = 0;

   using (var cnn = new SqlConnection(
          Properties.Settings.Default.universityConnectionString))
   {
      using (var cmd = new SqlCommand("UPDATE Student " +
              "SET FirstName = @FirstName, " +
              "lastName = @LastName, " +
              "birth = @birth " +
              "WHERE id = @id", cnn))
      {
        cmd.Parameters.Add(new SqlParameter("@FirstName", stu.FirstName));
        cmd.Parameters.Add(new SqlParameter("@LastName", stu.LastName));
        cmd.Parameters.Add(new SqlParameter("@id", stu.ID));
        cmd.Parameters.Add(new SqlParameter("@birth", stu.Birth));

        cnn.Open();
        rowsChanged = (int)cmd.ExecuteNonQuery();
        Properties.Settings.Default.Save();
      }
    }
    Properties.Settings.Default.Save();
    return (rowsChanged != 0);
  }

But when I call function no data is actually getting saved to the Database

Can someone tell me why?

  • 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-04T12:02:55+00:00Added an answer on June 4, 2026 at 12:02 pm

    With the entire solution and information you provided in chat, your code is fine. The problem is that the .mdf database file is set to "Copy to Output Directory": "Always" in your project. Change this property to "Copy if newer" (or "Do not copy" and move it to the bin folder yourself) and it will not overwrite your changes when you re-run the application. Importantly, you will not see the changes you make in your application reflected in your .mdf database file in the project’s root directory. It actually gets copied to the /bin folder and that’s where the changes are persisted. So, if you don’t change the "Copy to Output Directory" property, it will copy from your root to your /bin folder every time you build. Thus it appears that the changes aren’t being persisted, when they actually are.

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

Sidebar

Related Questions

I have written following function public void TestSB() { string str = The quick
I have written the following function but it's isn't returning anything when I run
I have written following function which checks whether start_date field is not empty and
I have written the following function which adds an event listener and registers the
I have written the following function: -- Gets stats for all markets CREATE OR
I have written the following function: it takes in a variable input_name ; The
So I am working on Problem 31 . I have written the following function
i have written following function in JS which is called on click of some
I have written the following template function for summing the contents of a std::vector
I have written the following function in a bash script but it is not

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.