retained inserted data in sql server compact table
-
Thursday, March 15, 2012 6:33 AM
Hi all,
I am able to insert data in SQL Server Compact table successfully but whenever i clean and rebuild my solution, the data is washed out of database i.e. after cleaning and rebuilding my solution, i am not able to retrieve data from database.
Following is my code snippet:
SqlCeConnection cn = new SqlCeConnection(@"Data Source=|DataDirectory|\applicationDB.sdf");
if (cn.State == ConnectionState.Closed)
{
cn.Open();
}
SqlCeCommand cmd;
string sql = "INSERT INTO userTable Values ('"+textBox1.Text+"' , '"+textBox2.Text+"')";
cmd = new SqlCeCommand(sql, cn);
try
{
cmd.ExecuteNonQuery();
lblResults.Text = "values inserted successfully!!";
}
catch (SqlCeException sqlexception)
{
MessageBox.Show(sqlexception.Message, "Oh Fudge.", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Fooey.", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
cn.Close();
}could anybody please throw some light on my code?
Thanks in anticipation
All Replies
-
Thursday, March 15, 2012 5:55 PMModerator
Look for a copy of your database in the bin/debug folder! See http://erikej.blogspot.com/2010/05/faq-why-does-my-changes-not-get-saved.htmlPlease mark as answer, if this was it. Visit my SQL Server Compact blog
- Proposed As Answer by willsonsingh Friday, March 16, 2012 8:42 AM
- Marked As Answer by KJian_ Wednesday, March 21, 2012 3:44 AM
-
Friday, March 16, 2012 8:42 AM
Hello,
I agree with Erik. Have a look at the link posted by him.

