0

I using a .sdf SQL server compact edition database and i want to insert data into it, but it didn't inserts!

My code:

string queryString = "INSERT INTO words(rus) VALUES(@wordp)";

SqlCeCommand cmd = new SqlCeCommand(queryString, conn);
cmd.Parameters.Add(new SqlCeParameter("@wordp", textBox1.Text));

cmd.ExecuteNonQuery();

cmd.Dispose();
conn.Close();

Connection opened correctly, and SELECT queries executes sucessfully. But after inserting data it's not inserts! I haven't any errors or warnings, and cmd.ExecuteNonQuery() return value 1 - query is executed correctly, but data not inserts!

In what could be the problem?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Roman Nazarkin
  • 2,209
  • 5
  • 23
  • 44
  • If its returning 1, then it means row is inserted. How are you checking if record is inserted or not? – Yahya May 07 '13 at 11:28
  • Maybe this post is useful for you [Insert problems to .sdf database C#](http://stackoverflow.com/questions/15663344/insert-problems-to-sdf-database-c-sharp) – Maryam Arshi May 07 '13 at 11:29
  • @Yahya, I checked - it is not exists. – Roman Nazarkin May 07 '13 at 11:29
  • @RomanNazarkin Using same connection, do a Select on same table. And check if newly inserted record is there. – Yahya May 07 '13 at 11:31
  • Please check if the connection string used in code is the same connection string used to search for the inserted record (using Server Explorer?) – Steve May 07 '13 at 11:33
  • I don't see anything wrong on this code. Are you sure `conn` is right? What is `textBox1.Text` value? – Soner Gönül May 07 '13 at 11:34
  • @marc_s we don't see where `conn` on created; it is impossible to say whether it is opened or not, but the OP certainly wouldn't get a result of `1` if it wasn't open - they would get an exception instead, strongly suggesting that this is not the problem – Marc Gravell May 07 '13 at 11:37

1 Answers1

4

This is usually simply an error of looking in the wrong file when debugging.

  • the original database is (generally) in your project directory
  • when you build, the project output including a copy of the database is copied to bin\debug or bin\release
  • during execution, you are editing the copy in bin\debug or bin\release
  • if you then stop and look at the version in your project directory, you won't see any changes, because you didn't edit that file (you edited the version in bin\debug or bin\release)
  • if you rebuild your project, you will often (depending on settings) overwrite the copy in bin\debug or bin\release, throwing away any changes
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900