Please I have been trying this code below to insert and delete record from my db but it compiles and when I check my db I dont see the update to show the query worked. But surprisingly if I use a select statement It gives me a sign that the query executed.
I would paste the logic that I am using to delete below (class code)
class Logic
{
SqlCeConnection con = null;
//code the constructor of the class
public Logic() {
//now we are going to collect the database configuration string
string connectionString = ConfigurationManager.ConnectionStrings["ConnectedCrud.Properties.Settings.DatabaseConnectionString"].ConnectionString;
con = new SqlCeConnection(connectionString);
Console.WriteLine(con.Database);
}
//This method is going to delete from the database
public void deleteValue(int r){
int k = 0;
string sql = string.Format("delete from Details where id = {0}",r);
using (SqlCeCommand command = new SqlCeCommand(sql, this.con)){
try
{
//open the connection
this.con.Open();
k = command.ExecuteNonQuery();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally{
this.con.Close();
}
}
if (k > 0)
{
Console.WriteLine("The rows as been deleted");
}
else
Console.WriteLine("The row was not deleted");
}
}
I have looked and looked and I am tried of looking. Is there something that I am suppose to do to my db to make my codes work. I have tried codes from two different textbooks on connected layer. But they give me the same confusing result.