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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:41:33+00:00 2026-06-06T11:41:33+00:00

When i try to insert the value from the textbox into the database, the

  • 0

When i try to insert the value from the textbox into the database, the values are not being updated in the database. But the newly inserted rows are temporarily available, after inserting when i use select query to get the rows, the new rows are available. When i close the solution and open it again, the newly insert rows are gone. The table in the database explorer is always not updated.

Here is my code.

            string connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True";
            string na = textBox1.Text;
            int ag = int.Parse(textBox2.Text);
            string ci = textBox3.Text;
            using (SqlConnection connection = new SqlConnection(connectionString))
            {

                using (SqlCommand insertCommand = connection.CreateCommand())
                {
                    insertCommand.CommandText = "INSERT INTO address(name,age,city) VALUES (@na,@ag,@ci)";
                    insertCommand.Parameters.AddWithValue("@na", na);
                    insertCommand.Parameters.AddWithValue("@ag", ag);
                    insertCommand.Parameters.AddWithValue("@ci", ci);


                    insertCommand.Connection.Open();
                    insertCommand.ExecuteNonQuery();
                    insertCommand.Connection.Close();
                    MessageBox.Show("finish");

                }

                //connection.Close();
            }

The table name is “address” and has three fields name(varchar(50)),age(int),city(nchar(10))
Please help.

  • 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-06T11:41:34+00:00Added an answer on June 6, 2026 at 11:41 am

    You said “C:\Users\Thangamani\documents\visual studio 2010\Projects\AddressBook\AddressBook\bin\Debug\” in the error. You are attaching to the local copy during debug.

    Now that you are not copying the database over, that mdf file does not exist, hence the error.

    Change your connection string to access the original database, not the local copy (which you are not making anymore).

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

Sidebar

Related Questions

I am trying to insert the values into cmdmysql.Parameters.Add using values from array. But
If I try this statement: INSERT INTO TerminalEventChild (id,stringValue) VALUES (64,'version123|'); MySQL fail with
I insert data from a typed dataset into my MSSQL database by using SqlBuldCopy
When I try to insert the current table into my table in SQL I
When I try to insert an object into my map, it throws the following
Getting a MySQL error message when I try to insert a text message from
I am getting an error when I try to insert an item into a
I have worked on sample application for insert the data into SqliteDb and try
I have a simple script which inserts values from a text file into a
How can I get the selected value from DetailsView to a textbox? So far

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.