Hi,

I have managed to create a connection via SQL Compact server to a local SDF database. I am able to query the data and retrieve the information. The only problem is trying to delete a record. When I run the code no error's are produced but the record is still there even after refreshing the table. Any ideas? Thanks.

private void buttDel_Click(object sender, EventArgs e)
        {
            SqlCeConnection conn = null;

            try
                {
                    //Connect to database
                    conn = new SqlCeConnection("Data Source=Database1.sdf; Persist Security Info=False");
                    conn.Open();                   

                    if (txtName.Text != "")
                    {
                        SqlCeCommand cmd = conn.CreateCommand();
                        cmd.CommandText = "DELETE FROM SignIn WHERE Username='" +txtName.Text + "'";
                        cmd.ExecuteNonQuery();

                        label29.Text = "User(" + txtName.Text+ ")has been deleted";                        
                    }
                }
                 catch (Exception p)
                        {
                            string errorString = p.Message;
                            MessageBox.Show(errorString);
                        }
                        finally
                        {
                            conn.Close();
                        }
            }

There are two same named database files (other .sdf is located under bin folder). Please use absolute path of database.

conn = new SqlCeConnection(@"Data Source=c:\folder1\Database1.sdf; Persist Security Info=False");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.