Exemplo n.º 1
0
        public bool Insert(roomClass r)
        {
            //Creating a default return type and setting its value to false
            bool isSuccess = false;
            //step1:Connect Database
            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                //Step2:writing sql query
                string sql = "INSERT INTO tbl_room(buildingName,roomName,floorNo,capacity,type) VALUES (@buildingName,@roomName,@floorNo,@capacity,@type)";
                //creating cmd using sql and conn
                SqlCommand cmd = new SqlCommand(sql, conn);
                //Create a parameters to add data
                cmd.Parameters.AddWithValue("@buildingName", r.BuildingName);
                cmd.Parameters.AddWithValue("@roomName", r.RoomName);
                cmd.Parameters.AddWithValue("@floorNo", r.FloorNo);
                cmd.Parameters.AddWithValue("@capacity", r.Capacity);
                cmd.Parameters.AddWithValue("@type", r.Types);


                //onnection open here
                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                //If the query run success rows>0
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
Exemplo n.º 2
0
        public bool Delete(roomClass r)
        {
            //Creating a default return type and setting its value to false
            bool isSuccess = false;
            //step1:Connect Database
            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                //Step2:writing sql query
                string sql = "DELETE FROM tbl_room WHERE roomID=@roomID";
                //creating cmd using sql and conn
                SqlCommand cmd = new SqlCommand(sql, conn);
                //Create a parameters to add data
                cmd.Parameters.AddWithValue("@roomID", r.RoomId);

                //onnection open here
                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                //If the query run success rows>0
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }