예제 #1
0
        //Method to Delete
        public bool Delete(jobCard c)
        {
            bool isSuccess = false;

            SqlConnection conn = new SqlConnection(myconnstring);

            try
            {
                string sql = "DELETE FROM allJob where Id=@Id";

                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@Id", c.Id);

                conn.Open();

                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
예제 #2
0
        //Update Method
        public bool Update(jobCard c)
        {
            bool isSuccess = false;

            SqlConnection conn = new SqlConnection(myconnstring);

            try
            {
                string sql = "UPDATE allJob SET Name=@Name, Price=@Price, Description=@Description Where Id=@Id";

                //Creating SQL command
                SqlCommand cmd = new SqlCommand(sql, conn);
                //Set Parameters
                cmd.Parameters.AddWithValue("@Name", c.Name);
                cmd.Parameters.AddWithValue("@Price", c.Price);
                cmd.Parameters.AddWithValue("@Description", c.Description);

                cmd.Parameters.AddWithValue("@Id", c.Id);

                conn.Open();

                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
예제 #3
0
        //Inserting Data Into DataBAse
        public bool Insert(jobCard c)
        {
            bool IsSuccess = false;

            //step1:connect database
            SqlConnection conn = new SqlConnection(myconnstring);

            try
            {
                string     sql = "INSERT INTO allJob(Name, Price, Description)VALUES(@Name, @Price, @Description)";
                SqlCommand cmd = new SqlCommand(sql, conn);

                cmd.Parameters.AddWithValue("@Name", c.Name);
                cmd.Parameters.AddWithValue("@Price", c.Price);
                cmd.Parameters.AddWithValue("@Description", c.Description);

                //connection open here
                conn.Open();
                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    IsSuccess = true;
                }
                else
                {
                    IsSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }
            return(IsSuccess);
        }