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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:30:26+00:00 2026-06-06T13:30:26+00:00

This is my code below. The program runs fine. I don’t get any exceptions.

  • 0

This is my code below. The program runs fine. I don’t get any exceptions. But in the end, the table doesn’t contain the newly inserted row. (Note, the connection string is correct).

string Name = "myname";
string Age = "myage";

string sql = "INSERT INTO Student (Name, Age) VALUES ('" + Name + "','" + Age + "')";

SqlConnection conn = new SqlConnection(ConfigHelper.GetConnectionString());
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
conn.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-06-06T13:30:27+00:00Added an answer on June 6, 2026 at 1:30 pm

    First of all: start using parametrized queries! Otherwise your code is always open to SQL injection attacks – not something you want to have to deal with.

    Assuming you are using this feature (depends on the connection string, which you haven’t shown us in the original question): the whole User Instance and AttachDbFileName= approach is flawed – at best! Visual Studio will be copying around the .mdf file and most likely, your INSERT works just fine – but you’re just looking at the wrong .mdf file in the end!

    If you want to stick with this approach, then try putting a breakpoint on the myConnection.Close() call – and then inspect the .mdf file with SQL Server Mgmt Studio Express – I’m almost certain your data is there.

    The real solution in my opinion would be to

    1. install SQL Server Express (and you’ve already done that anyway)

    2. install SQL Server Management Studio Express

    3. create your database in SSMS Express, give it a logical name (e.g. VictoryDatabase)

    4. connect to it using its logical database name (given when you create it on the server) – and don’t mess around with physical database files and user instances. In that case, your connection string would be something like:

      Data Source=.\\SQLEXPRESS;Database=VictoryDatabase;Integrated Security=True
      

      and everything else is exactly the same as before…

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

Sidebar

Related Questions

This code below doesn't work correctly since my MFC program is in unicode circumstance.
I'm working on a picture select/crop program and using this code below: http://www.androidworks.com/crop_large_photos_with_android/comment-page-1#comment-969 As
The code below is creating a server to communicate with clients.This code works fine
OS: Windows server 03 Python ver: 2.7 For the code below, its runs fine
This code below is for executing ls -l | wc -l. In the code,
This code below works in all web browsers except IE: <input type="text" name="passwordLogin" value="Password"
The code below create one circle inside the windows form. This code compiled without
i am using this code below to dynamically capture the name of the button
I have this code below. As you can see I am passing two variables
Hi I'm using this code below to let a user draw their signature on

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.