Skip to content Skip to sidebar Skip to footer

Need Help On Deleting Row(s) From A Sql Server Ce Database

Another question today. This time, I'm having trouble deleting a row from a SQL Server CE database. private void Form1_Load(object sender, EventArgs e) { // Create a connec

Solution 1:

Note that: executing command with Command.ExecuteXXX() requires the connection to be open first. Filling data into DataSet using SqlDataAdapter.Fill doesn't require that because it handles that internally. Executing the SQL query this way is direct and don't require any Update method call on adapter (as you add in your code after deleting). Update is just for saving changes made on your DataSet.

    //Delete from the database
    using (SqlCeCommand com = new SqlCeCommand("DELETE FROM accounts WHERE Id = 0", connection))
    {
        if(connection.State == ConnectionState.Closed) connection.Open();
        com.ExecuteNonQuery();
    }

Post a Comment for "Need Help On Deleting Row(s) From A Sql Server Ce Database"