none
retained inserted data in sql server compact table

    Question

  • 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

    Thursday, March 15, 2012 6:33 AM

Answers

All replies