Start New Discussion within our Software Development Community

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");
This question has already been answered. Start a new discussion instead.