0

Please I am new to the ADO.NET connected layer. But I have been able to learn how to communicate with my db effectively on the connected layer. But I notice that wen I execute an insert, update or a delete sql. I dont see the changes in the database. I but I am sure that the changes are effected cause if i run a select statement i usually see a difference in the data retrieved. but I confuse on the reason y i dont see the new data inserted when i check the db rows from visual studio. I am using ms sql db or ms sql db compact version. i use either. bt same result on both.

2
Contributors
3
Replies
11
Views
4 Years
Discussion Span
Last Post by skliz
0

Please is there something that I am suppose to do to my database. Cause the code compiles and execute without displaying errors.
I only know values are inserted into my table when I run a select statement on that table. But opening the table on my visual studio IDE i dont see the new records there.

0

Maybe we can help if you put your code and also the db structure. Otherwise ...Is difficult to imagine what is going wrong, if any thing is wrong.

0
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");

        }
}





Database structure

create table Details(

id int auto_increment primary key not null,
username varchar(20),
password varchar(20),
name varchar(20),
phone varchar(20)

);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.