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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:16:12+00:00 2026-05-23T14:16:12+00:00

I’ve checked other Stack Overflow questions to find answers, but I just can’t find

  • 0

I’ve checked other Stack Overflow questions to find answers, but I just can’t find a solution to this. I am trying to insert string data into a SQL CE (local database).

I can read from the database, but I cannot insert data, regardless of whether I hard-code it or try to add it with parameters.

The table to be modified is called users. It has 3 columns: ID, name, email.

Here is the code I am using:

string connection = Properties.Settings.Default.LocalDBConnectionString;

using (var con = new SqlCeConnection(connection))
{
    con.Open();

    // (I also tried adding with parameters but couldn't get it working.)
    using (var com = new SqlCeCommand("INSERT INTO users (name, email) " +
                                      "VALUES (N'jimmy', N'email@jim.com')", con))
    {
        int numRowsAffected = com.ExecuteNonQuery();

        // This returns '1 row affected' but doesn't actually update the database
        Console.WriteLine(numRowsAffected);
        Console.ReadKey();
    }
}

Although the Console outputs 1, because 1 row is affected, when I go back into the database and check, it has not inserted the new data.

I was following this tutorial, but only the Read works, the Insert or write doesn’t work.

I also found this similar Stack Overflow question, but using parameters, still couldn’t get it to work.


Edit:

My connection string is:

Data Source=|DataDirectory|\LocalDB.sdf

I don’t know how to find the Build Settings, it is a Local Database I created within the console application solution, It is stored in the project directory.

I am in “Debug” configuration if that helps?


Here is another example I found on the internet:

SqlCeConnection con = new SqlCeConnection(Properties.Settings.Default.LocalDBConnectionString);
con.Open();

SqlCeCommand comInsert = new SqlCeCommand ("INSERT INTO users(name, email) VALUES('value 1', 'value 2')", con);
comInsert.ExecuteNonQuery();

SqlCeCommand comSelect = new SqlCeCommand("SELECT * FROM users", con);
SqlCeDataReader reader = comSelect.ExecuteReader();

while (reader.Read())
{
    Console.WriteLine("{0} {1}", reader["name"], reader["email"]);
    Console.ReadKey();
}

con.Close();

I just copied and pasted this in, and changed the main variables. This example temporarily inserts the data, but when I go to Visual Studio’s Server Explorer and view the table, it hasn’t updated.

  • 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-23T14:16:12+00:00Added an answer on May 23, 2026 at 2:16 pm

    Are you sure that the database you INSERT into and the database you’re looking at with Server Explorer are the same one?

    Remember, we’re talking about a file-based DB here (SQL Server CE). So it could be that you’re INSERTing into a copy of your DB and then look at the (unchanged) original.

    • Is the DB file part of your solution? If so, does it get copied to the output directory (e.g. bin\Debug)? Check the properties of the corresponding solution item, like in the screenshot below (sorry for it being in German):

      Screenshot showing a 'Local Database' project item and its 'Copy to output directory' property setting

    • Where exactly does DataDirectory in the connection string point to? If you’re not sure, replace it with something absolute for the time being and see if that solves your problem.

    Make double sure that your connection string really points to the database you’re looking at with Server Explorer!

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

Sidebar

Related Questions

I know there's a lot of other questions out there that deal with this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.